in reply to position after global matches?
You can achieve that by using a lookahead or lookbehind assertions. The former will give you the start positions of the matches. The latter the ends (as you've requested).
$_ = 'TATATATATATA'; while (/(?=TATA)/g) { print "Matched 'TATA' at position ", pos, "\n"; };; Matched 'TATA' at position 0 Matched 'TATA' at position 2 Matched 'TATA' at position 4 Matched 'TATA' at position 6 Matched 'TATA' at position 8 $_ = 'TATATATATATA'; while (/(?<=TATA)/g) { print "Matched 'TATA' at position ", pos, "\n"; } Matched 'TATA' at position 4 Matched 'TATA' at position 6 Matched 'TATA' at position 8 Matched 'TATA' at position 10 Matched 'TATA' at position 12
|
|---|