Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Regular expression help: why does this not match?

by chargrill (Parson)
on Jan 18, 2007 at 23:00 UTC ( #595366=note: print w/replies, xml ) Need Help??


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.



--chargrill
s**lil*; $*=join'',sort split q**; s;.*;grr; &&s+(.(.)).+$2$1+; $; = qq-$_-;s,.*,ahc,;$,.=chop for split q,,,reverse;print for($,,$;,$*,$/)

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://595366]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others perusing the Monastery: (7)
As of 2019-10-18 07:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?