Just wanted to point out that the pair:

allo ^ao$

doesn't work, because this regex matches "ao" on a line by itself.  you
would have to perform two matches, one for "^a" and another for "o$" in
order to match te string "allo" this way.  As for why the '/' doesn't
cooperate, it has to do with the fact that when you parse it as part of a
variable, the '/' becomes part of the string, rather than a trigger to the
regex evaluator that this is a regular expression.  I noticed the same thing
in AWK, if I put the /al/ inside quotes, thus, "/al/" it didn't match, but
without the quotes, it worked fine.

> -----Original Message-----
> From: Robin Lavallee (LMC) [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, May 22, 2001 8:23 AM
> To: [EMAIL PROTECTED]
> Subject: Dynamic regular expressions
> 
> 
> 
> Hi people,
> 
>       I need to match string against regular expressions that are only
> known at run-time. I'm having problems doing it so I made a small test
> script like the following :
> 
> #!/net/tcmvega35/data1/automation/perl/bin/perl -w
> 
> use strict;
> die "test.pl [string] [regex]" unless $#ARGV == 1;
> 
> if ($ARGV[0] =~ $ARGV[1])
> {
>       print "$ARGV[0] matches $ARGV[1]\n";
> }
> else
> {
>       print "$ARGV[0] does not match $ARGV[1]\n";
> }
> 
> On the command lines, the following happend
> 
> allo al               => match
> allo /al/             => no match (should match, no ?)
> allo lo$              => match
> allo ^al              => match
> allo ^ao$             => no match (should match, no ?)
> 
> Questions :
> 
>       - Why don't I need the regular expression delimiters (/), is it
> implicit when using variables ?
>       - If I don't add them (/), will it still work for all cases ?
>       - Why doesn't the last case work ?
> 
> Thanks !
> 
> -Robin
> 

Reply via email to