CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Regular Expressions: What is significance of (?s) in s/(?s)Title/xxx/g regexp?: Edit Log



poly4life
Novice

Mar 23, 2011, 8:23 AM


Views: 2775
What is significance of (?s) in s/(?s)Title/xxx/g regexp?

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.


Code
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:

Code
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)


Edit Log:
Post edited by poly4life (Novice) on Mar 23, 2011, 8:26 AM
Post edited by poly4life (Novice) on Mar 23, 2011, 8:26 AM
Post edited by poly4life (Novice) on Mar 23, 2011, 8:30 AM
Post edited by poly4life (Novice) on Mar 23, 2011, 8:32 AM
Post edited by poly4life (Novice) on Mar 23, 2011, 9:16 AM
Post edited by poly4life (Novice) on Mar 23, 2011, 9:32 AM
Post edited by poly4life (Novice) on Mar 23, 2011, 10:31 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives