Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

'multiline' or 'single string' in regex?

Status
Not open for further replies.

AMiSM

Technical User
Joined
Jan 26, 2006
Messages
128
Location
US

Hi, folks!
In a substitution regex, when would you use the 'm' option, and when would you use the 's' option?
 
'm' is for if you want the regexp to evaluate each line in a string:

Code:
my $string = q~mary had a little lamb
it's fleece was white as snow
everywhere that mary went
the lamb was sure to go~;

$string =~ s/^/foo/mg;

print $string;

prints:

foomary had a little lamb
fooit's fleece was white as snow
fooeverywhere that marry went
foothe lamb was sure to go


's' treats the entire string as one line:

Code:
my $string = q~mary had a little lamb
it's fleece was white as snow
everywhere that marry went
the lamb was sure to go~;

$string =~ s/^/foo/sg;

print $string;

prints:

foomary had a little lamb
it's fleece was white as snow
everywhere that marry went
the lamb was sure to go
 

ok.
thanks!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top