in reply to Regular Expressions and Question Marks
Single quotes preserve your backslash, double quotes use it, putting, as you asked, a literal quotation mark in your string. This is different from single quotes which put in a backslash then a question mark when presented with the same string.$matchtext1 = "http://www.new.site/somenewpage.pl\?"; print "$matchtext1\n"; $matchtext2 = 'http://www.new.site/somenewpage.pl\?'; print "$matchtext2\n";
s/somenewpage.pl??/somenewpage.pl?/So, "somenewpage.p" turns into "somenewpage.pl?" and you still have the "l?" leftover. Hence, "somenewpage.pl?l?". Why does it do this? With a single question mark, it would be greedy and grab the 'l', since there is one there. The second question mark tells it to be conservative and use the shortest possible match, which in this case is the "0" part of "0 or 1 instances of" meaning of "?".
$matchtext = "http://www.foo.bar/somepage.pl?"; $substitutetext = "http://www.new.site/somenewpage?"; s/\Q$matchtext\E/$substitutetext/;
|
|---|