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

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

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



Mar 23, 2011, 8:23 AM

Post #1 of 3 (7768 views)
What is significance of (?s) in s/(?s)Title/xxx/g regexp? Can't Post


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:, 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)


Mar 23, 2011, 11:24 AM

Post #2 of 3 (7740 views)
Re: [poly4life] What is significance of (?s) in s/(?s)Title/xxx/g regexp? [In reply to] Can't Post

1) (?s)

Yes, since this is at the beginning of the left hand side, it applies to everything and could just be moved outside the regex and placed next to the g.

2) All the html files

My suggestion is that it's time to turn it into a script, but yes it's very possible.

3) instead of having ugly "\/" escapes.

My personal preference is to us s{}{} whenever i want to avoid leaning tower business. It's cleaner in my opinion, but s~ ~ ~ works for some.


Mar 24, 2011, 9:26 AM

Post #3 of 3 (7711 views)
Re: [miller] What is significance of (?s) in s/(?s)Title/xxx/g regexp? [In reply to] Can't Post

1) Thank you.

2) A script is a great idea (I'll make another thread for this). I was able to figure it out using a for loop in a batch file and execute the perl in single-line edit mode.

3) I should've realized this, something so simple. Thank you for pointing this out.


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

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