VingInMedina has asked for the wisdom of the Perl Monks concerning the following question:
Can anyone please explain to me what the first regular expression test will match, but the second one won't?
#!/usr/bin/perl use strict; use warnings; my $a = 'abc == 123'; if ($a =~ /^(.*?)==(.*)$/) { print "This will match\n"; print "First: $1\nLast: $2\n"; } if ($a =~ /^(.*?)\b==\b(.*)$/) { print "This will not match\n"; print "First: $1\nLast: $2\n"; }
I need to use the non-greedy match in the first part of the expression becuase I need to find the first occurrence of the '=='.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Regular Expression Question
by davido (Cardinal) on May 02, 2012 at 18:36 UTC | |
by VingInMedina (Acolyte) on May 02, 2012 at 19:52 UTC |