s and m modifiers

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

s and m modifiers

Doug Traylor
Fritz Borgstedt wrote:
In 1.3.3.2 (31) the modifiers for regexen like bombre and whitere are
changed from /si to /msi.

 The /s modifier treat a string as single line.  The "/s"  modifier 
overrides the $* setting. That is, no matter what $* contains, /s will
force "^" to match only at the beginning of the string and "$" to
match only at the end (or just before a newline at the end) of the
string. Together, as /ms, they let the "." match any character
whatsoever, while still allowing "^" and "$" to match, respectively,
just after and just before newlines within the string. 
Being a little dense this morning I couldn't get my head around what you were saying.  So, I did a little digging and found some more explanation of the modifiers s and m.  It seems you have added multiline matching ability in a single string where the was none before.  Is that correct?

I found this:

modifier s tells Perl to have . (full stop) match new line as well as anything else
modifier m tells Perl to have ^ and $ match at embedded new lines within the string.

and,

m     Treat string as multiple lines. That is, change "^'' and "$'' from matching at only the very start or end of the string to the start or end of any line anywhere within the string. 
s     Treat string as single line. That is, change ".'' to match any character whatsoever, even a line separators, which it normally would not match.

and,

# If you want the ^ marker and the $ marker to look at the
# start point and end point of *lines*, not at the start point
# and end point of the *string*, then you need the /m modifier.

A Google cache of a discussion at perlmonks about the s and m modifiers:
http://64.233.167.104/search?q=cache:dYgn44QNcekJ:www.perlmonks.org/%3Fnode_id%3D238272+perl+modifiers+/s+/m&hl=en&ct=clnk&cd=4

Hope this helps someone else,

Doug
-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Assp-test mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/assp-test
Reply | Threaded
Open this post in threaded view
|

Re: s and m modifiers

Doug Traylor
Doug Traylor wrote:
> Being a little dense this morning I couldn't get my head around what
> you were saying.  So, I did a little digging and found some more
> explanation of the modifiers s and m.  It seems you have added
> multiline matching ability in a single string where the was none
> before.  Is that correct?
OK I see now I was wrong, the /s did hit on multi lines too.

"The way I remember what /s and /m do is like this. I know that they
change the behaviour of regex metacharacters, but /s changes the
behaviour of a single metacharacter (.) and /m changes the behaviour of
multiple metacharacters (^ and $)."

"I think that's a useful mnemonic. And it may help people to remember
that those are the only things the /m and /s modifiers affect. The /s
modifier only affects whether "." will match a newline. The /m modifier
only affects whether ^ and $ can match at embedded newlines in the
middle of a string."

Sorry for my confusion,

Doug

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Assp-test mailing list
[hidden email]
https://lists.sourceforge.net/lists/listinfo/assp-test