Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re^4: Regex Tool

by a (Friar)
on Jul 01, 2006 at 14:22 UTC ( #558764=note: print w/ replies, xml ) Need Help??


in reply to Re^3: Regex Tool
in thread Regex Tool

Just a point here - something I finally got only after a number of rereadings of the section in J. Friedl's excellent Mastering Regular Expressions (O'Reilly) the /m and /s are a little more complicated.
/m: better remembered as 'multi' mode - affects 'multiple' (2) meta chars, the anchors (^ and $)
/s: 'single' mode - affects one meta char, the dot '.'

/s changes the dot's normal definition - match any char except a new line (\n). In single mode the dot can match \n too which allows regex phrases like:
.*

to match across the end of line. That all it does and so its why the "item.*" in your example matches the end of line.
/m changes the ^ and $ anchors from absolute beginning and end of string to match beginning and end of a line, as marked by new line chars. Which is useful w/ the '/g' option, for example:

local $/ = undef; my $whole_file = <>; # slurp while ( $whole_file =~ /^(.*)$/mg ) { # process line by line print "Got: $1\n"; }
Not a useful snippet but ... two notes - the '\n' on the print stmt and notice the diff if you put an 's' in the match options

a


Comment on Re^4: Regex Tool
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (15)
As of 2014-07-25 16:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (174 votes), past polls