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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.