in reply to Regex and \G
It prints:$a = "ab cdef gh ijklmn"; $b = "xyz"; while($a =~ /\G(\w\w)/g) { print "1: match in \$a: $1\n"; if($b =~ /\G(\w)/g) { print "2: match in \$b: $1\n"; } else { print "2: no match in \$b - replacing \$a\n"; $a = "AB CD EF"; } if($a =~ /\G(\s*)/g && length $1) { # The match itself never fails print "3: skipping whitespace in \$a\n"; } }
1: match in $a: ab 2: match in $b: x 3: skipping whitespace in $a 1: match in $a: cd 2: match in $b: y 1: match in $a: ef 2: match in $b: z 3: skipping whitespace in $a 1: match in $a: gh 2: no match in $b - replacing $a 1: match in $a: AB 2: match in $b: x 3: skipping whitespace in $a 1: match in $a: CD 2: match in $b: y 3: skipping whitespace in $a 1: match in $a: EF 2: match in $b: zLook how two regexes (1 and 3) match on $a, sharing the same pos pointer, and another one (2) matching on $b, using its own pointer, independently of the other.
What can one conclude from this?
|
|---|