in reply to regex problem: doesn't work on the first search but works on the second
output:use strict; use warnings; my $string = 'foo bar'; if ($string =~ m{bar}g) { print "bar\n"; } if ($string =~ m{foo}g) { print "foo\n"; } if ($string =~ m{bar}g) { print "bar\n"; }
without the /g it will print:bar bar
The /g will keep the current position in the string and as such you are later continuing your matching from that position. If you just want to match your entire string (as it seems in this case), simply try dropping the /g.bar foo bar
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: regex problem: doesn't work on the first search but works on the second
by Anonymous Monk on Nov 28, 2013 at 10:06 UTC | |
by AnomalousMonk (Archbishop) on Nov 28, 2013 at 19:52 UTC | |
by AnomalousMonk (Archbishop) on Nov 28, 2013 at 19:34 UTC |