in reply to Regular expression help: why does this not match?
Correct, ? is a regex meta character which means "Match 1 or 0 times". In your first example, your regex is looking for: http://www(any char)myurl(any char)/e(any char)ph(0 or 1 p)a.
Please note that the dot . also has special meaning - it means to match any character (also note that a dot qualifies as "any character" :-). You could specify \. to match a dot, but given that you want to match the question mark too, you might just be better off with \Q (quote the following regex metacharacters) (generally followed by \E (stop quoting regex metacharacters), too), i.e.:
$a = "http://www.myurl.com/e.php?a"; $b = "http://www.myurl.com/e.php?a"; if ($a =~ /\Q$b\E/) { print "FOUND\n"; } else { print "NOT FOUND\n"; }
Incidentally, $a and $b are bad names for variables, as they have special meaning to sort. And you might also have to fix up your shebang (!/usr/bin/perl should be #!/usr/bin/perl) in case you ever want to run your program via ./ instead of perl program.pl.
s**lil*; $*=join'',sort split q**; s;.*;grr; &&s+(.(.)).+$2$1+; $; = qq-$_-;s,.*,ahc,;$,.=chop for split q,,,reverse;print for($,,$;,$*,$/)
|
|---|