mdunnbass has asked for the wisdom of the Perl Monks concerning the following question:
Here's a quick question for you. I have looked at perlre, perlretut, and done some web-searching, and I am still unclear what to do.
If I have the following code:
The output I get is:$_ = 'TATATATATATA'; while (/TATA/g) { print "Matched 'TATA' at position ", pos, "\n"; }
So, obviously, the /g leaves me positioned at the end of each successive match. But, if I wanted to also match at positions 6 and 10, would I need to respecify pos to be the beginning of the previous match +1 character? Is there a better, more straightforward way to do this? Am I just missing something simple?Matched 'TATA' at position 4 Matched 'TATA' at position 8 Matched 'TATA' at position 12
Thanks
Matt
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: position after global matches?
by BrowserUk (Patriarch) on May 29, 2007 at 16:32 UTC | |
|
Re: position after global matches?
by FunkyMonk (Bishop) on May 29, 2007 at 16:26 UTC | |
|
Re: position after global matches?
by blazar (Canon) on May 29, 2007 at 16:28 UTC | |
|
Re: position after global matches?
by duff (Parson) on May 29, 2007 at 18:56 UTC |