| e |
Evaluate the replacement side as an expression |
| i |
Turn off case sensitivity |
| m |
Treat a string as multuple lines. Let ^ and $ match next to embedded \n |
| o |
Compile pattern only once. Used to optimize the search |
| s |
Treat string as single line when newline is embedded. Let . match newline |
| x |
Allows whitespace and comments whithin the regex |
| g |
Replace globally, i.e. find all occurrences |
| gc |
Alows continued search after failed /g match |
| - gc - |
| |
$_ = "123456abc7x";
$num = "\d\d\d";
$let = qr/[a-zA-Z]{3}/; |
| 1. |
while (1) { |
| |
if (m/($num)/g) { print "NUM: $1\n"; } |
| |
elsif (m/($let)/g) { print "LET: $1\n"; } |
| |
else { print "pos = " . pos() "\n" and last; } |
| |
} |
| |
# infinitive loop |
| |
| 2. |
while (1) { |
| |
if (m/\G($num)/g)
{ print "NUM: $1\n"; } |
| |
elsif (m/\G($let)/g)
{ print "LET: $1\n"; } |
| |
else { print "pos = " . pos() "\n" and last; } |
| |
} |
| |
# NUM: 123 |
| |
# NUM: 456 |
| |
# Use of uninitialized value in concatenation ... |
| |
# pos = |
| |
| 3. |
while (1) { |
| |
if (m/\G($num)/gc)
{ print "NUM: $1\n"; } |
| |
elsif (m/\G($let)/gc)
{ print "LET: $1\n"; } |
| |
else { print "pos = " . pos() "\n" and last; } |
| |
} |
| |
# NUM: 123 |
| |
# NUM: 456 |
| |
# LET: abc |
| |
# pos = 9 |