- 论坛徽章:
- 145
|
回复 1# gaojianchun1984
if($str =~ m/b/g){ ... } # note: ab
found the "b" and keep the position 2 (after b)
if($str =~ m/a/g){ ... } # note: ab
cannot find the "a" after "b" (postion 2)
$ perldoc perlretut
NAME
perlretut - Perl regular expressions tutorial
...
Global matching
The final two modifiers we will discuss here, "//g" and "//c", concern
multiple matches. The modifier "//g" stands for global matching and allows
the matching operator to match within a string as many times as possible.
In scalar context, successive invocations against a string will have "//g"
jump from match to match, keeping track of position in the string as it
goes along. You can get or set the position with the "pos()" function.
|
|