Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

comment on

( #3333=superdoc: print w/replies, xml ) Need Help??
Well, this does seem curious:
$ perl -v This is perl, v5.6.1 built for i586-linux ... $ perl -e '$u="http://www.domain.com/hi.html?a=b&c=d"; print $u,$/; $u=~s/(.*?)\?(.*?)/$1/gs; print $u,$/;'
produces:
http://www.domain.com/hi.html?a=b&c=d http://www.domain.com/hi.htmla=b&c=d
But you said that you only wanted the first part (before the "?"), so why did you put parens around the second part? It does work as desired this way:
$ perl -e '$u="http://www.domain.com/hi.html?a=b&c=d"; print $u,$/; $u=~s/(.*?)\?.*/$1/; print $u,$/;' http://www.domain.com/hi.html?a=b&c=d http://www.domain.com/hi.html
For that matter, whether or not you use the following part as well, why not split:
$ perl -e '$u="http://www.domain.com/hi.html?a=b&c=d"; print $u,$/; ($ub,$ue)=split(/\?/,$u,2); print "$ub :: $ue",$/;' http://www.domain.com/hi.html?a=b&c=d http://www.domain.com/hi.html :: a=b&c=d
Still, the initial example is baffling, and I hope someone can explain why it should behave the way it did, just for our communal peace of mind. The final "gs" is of course superfluous for this example -- the behavior is the same with or without those qualifiers on the regex. (And "extra strength" is not really an appropriate reason for using them, anyway; check their descriptions in perlre to see what their proper, intended functions are.)

In reply to Re: Regex Bug? by graff
in thread Regex Bug? by mt2k

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2022-12-04 18:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?