gohaku wrote:
Hi everyone,
Sorry for asking this question again for what must be the umpteenth time but I have a problem with
the g modifier when matching. I have read Newsgroup Postings about this topic including:
"What good is \G in a regular expression?"
G is likely best for s/// syntax as there is a better (?:test) for pattern matching in general:
$_ = "I match it All, so you dont have to";
s%a%_%ig;
Please, please don't do that. Using weirc chars obfuscates the code. Always uses slashes unless the regex contains multiple slashes or backslashes. When you do have to use a different regex quote character, please pick one that is not so noisy.
print "$_";
you get I m_tch it _ll, so you dont h_ve to
G just causes the match to match everywhere the pattern is to be found. But NOT beyond the end of the line (\n) which is a logical record separator...
The \G modifier causes the match to begin at the position of the last match. Ex.
while ('a 1 b 2 c 3' =~ /\G\D+(\d)/g) { print $1 }
=> 123
1st iteration: 'a 1 b 2 c 3' p ^ 2nd iteration 'a 1 b 2 c 3' p ^ 3rd iteration 'a 1 b 2 c 3' p ^
Where p marks the pos where the search begins, which is the position of the last match. And ^ marks the captured match.
See 'perldoc perlre'
Randy.
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>