in reply to Re: mysteries of regex substring matching (updated)
in thread mysteries of regex substring matching
I'm sure we discussed this technique before, but I can't find it in the archives.
Do you remember a thread? :)
well I deciphered it in the meantime, it's not operating on match-groups but the /x /g ° modifier.
That'll repeat a search where the last match ended, and return all results in list context till it fails
DB<139> p 0123456789abcdefghijklmnopqrstuvwxyz DB<139> x m{ .... }xg 0 0123 1 4567 2 '89ab' 3 'cdef' 4 'ghij' 5 'klmn' 6 'opqr' 7 'stuv' 8 'wxyz' DB<140>
with a negative look-behind (?<! ) we can filter out all matches after the initial 4
DB<140> x m{ (?<! (?: .... ){4} ) .... }xg 0 0123 1 4567 2 '89ab' 3 'cdef' DB<141>
an or condition | helps matching after the fail.
DB<142> x m{ (?<! (?: .... ){4} ) .... | .+ }xg 0 0123 1 4567 2 '89ab' 3 'cdef' 4 'ghijklmnopqrstuvwxyz' DB<143>
Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery
°) thanks AnomalousMonk++ for spotting :)
|
|---|