in reply to Re: Modifying pos() from within (?{...})
in thread Modifying pos() from within (?{...})
Thanks for this, it's clear and explains why the (?{...}) solution didn't (and could never) work.
I've not used \G and /c before. From reading perlre I now understand that \G essentially 'anchors' that point to index pos() into the string. I'm a little confused by the description for the /c modifier. From perlre v5.24:
c - keep the current position during repeated matching
and from the referenced perlretut
A failed match or changing the target string resets the position. If you don't want the position reset after failure to match, add the "//c", as in "/regexp/gc".
I assume then, should the data I'm parsing with the regex be well formatted, then pos() will never be reset and so the /c modifier is not needed? But were any matches fail, things would break
Is this a correct understanding of \G and /c?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Modifying pos() from within (?{...})
by haukex (Archbishop) on Apr 26, 2018 at 13:50 UTC |