Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re^2: Regex in if statement

by finfan (Acolyte)
on Mar 18, 2014 at 19:52 UTC ( #1078856=note: print w/ replies, xml ) Need Help??


in reply to Re: Regex in if statement
in thread Regex in if statemetn

Doesn't seem to work. #MO and # MO do not match. Tried the regex tester at http://www.internetofficer.com/seo-tool/regex-tester/ and it says "no match"


Comment on Re^2: Regex in if statement
Re^3: Regex in if statement
by hippo (Vicar) on Mar 18, 2014 at 19:57 UTC

    Sure they do:

    $ cat 1078855.pl use warnings; use strict; while (<DATA>) { print if /^#\s*[a-z]+/i; } __DATA__ #MO # MO #mo # mo # 555 $ perl 1078855.pl #MO # MO #mo # mo $
Re^3: Regex in if statement
by 2teez (Priest) on Mar 18, 2014 at 21:09 UTC

    Hi finfan,

    ..Doesn't seem to work. #MO and # MO do not match. Tried the regex tester at http://www.internetofficer.com/seo-tool/regex-tester/ and it says "no match"..

    I know the code posted by toolic worked, I wanted to find out why it wasn't working on the website you mentioned. Tried it out and it worked with the following result:

    Regular Expression Test Results Tested pattern: ^#\s*[a-z]+ Applied options: the comparison was case-insensitive String 1: #MO Result : true String 2: # MO Result : true String 3: #mo Result : true String 4: # mo Result : true String 5: # 555 Result : false
    May be the question, one should be asking is: How are you doing these regexp?

    If you tell me, I'll forget.
    If you show me, I'll remember.
    if you involve me, I'll understand.
    --- Author unknown to me
Re^3: Regex in if statement
by kcott (Abbot) on Mar 19, 2014 at 07:17 UTC
    "Doesn't seem to work. #MO and # MO do not match."

    That sounds like you forgot the 'i' modifier at the end of "/^#\s*[a-z]+/i".

    "Tried the regex tester at http://www.internetofficer.com/seo-tool/regex-tester/ and it says "no match""

    That site clearly states "We use Perl-style regular expressions." (not Perl regular expressions). It also seems to have limited functionality: it has a checkbox for the 'i' modifier and nothing for any of the other modifiers (see /PATTERN/msixpodualgc in "perlop: Regexp Quote-Like Operators").

    Why not try it in a real perl script. As ++toolic provided you with the complete code, it's a simple copy-paste operation.

    -- Ken

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1078856]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (13)
As of 2015-07-06 12:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The top three priorities of my open tasks are (in descending order of likelihood to be worked on) ...









    Results (74 votes), past polls