
poly4life
Novice
Mar 23, 2011, 8:23 AM
Post #1 of 3
(6786 views)
|
What is significance of (?s) in s/(?s)Title/xxx/g regexp?
|
Can't Post
|
|
Hello, I am trying to interpret and analyze a regular expression and I need some help. Please note it is not my regular expression and I also have simplified it to narrow in on the issue, at the moment. Note: I am using strawberry Perl and Windows XP. I have created a Windows batch file which runs a perl program in single-line edit mode.
perl -pi.bak -e "/(?s)Title/xxx/g" *.html Now I have never used "(?s)" in my regular expressions, both in perl and PHP, so I had to look it up and discover it is an extended pattern modifier and may be used in conjunction with the "/" delimiter. What is the significance of this extended pattern modifier and why can't I just place the "s" after the second "/" delimiter, like "g"? See this link for details: http://perldoc.perl.org/perlre.html, and scroll to "Extended Patterns". Thank you for your help. A couple more items: Is there a way I can convert this:
perl -pi.bak -e "s/(?s)Title/xxx/g" *.html To a Perl program which will search..replace regex. for all files in a directory with a .html extension (i.e. *.html)? And is there a way to automatically escape forward slashes, similar to \Q, automatically escaping all quotes in a string? If so, where do I put it? So, I thought if I have a lot of html close tags, I can make the code look more clean by escaping the backslashes automatically, instead of having ugly "\/" escapes. Edit: I can just use ~pattern~replacement~g *.html. Duh. Thanks again.
(This post was edited by poly4life on Mar 23, 2011, 10:31 AM)
|