in reply to Re: Regex: matching character which happens exactly once
in thread Regex: matching character which happens exactly once
This is because $1 is a global var will keep match instead of erasing when backtracking.
FWIW I tried something similar by capturing the following character in $2 for the next run:
m/ ^ (?:(?!\2).)*? (.) (?=(.|$)) (?!.*\1) /x
But couldn't get it to work, probably because the regex engine is not considering another defined \2 while backtracking. (or probably b/c I was too tired last night)
DB<310> @inp = glob '{a,b}'x3 DB<311> ;m/ ^ (?:(?!\2).)*? (?{say "<$_ $2>"}) (.) (?=(.|$)) (?!.* +\1) /x and say ("found $1 in $_") for @inp <aaa > <aab > <aba > <aba b> found b in aba <abb > found a in abb <baa > found b in baa <bab > <bab a> found a in bab <bba > <bbb > DB<312>
probably I'm having a bug in my logic, experts to the rescue! ;-)
Didn't have the time yet for proper debugging.
Cheers Rolf
(addicted to the Perl Programming Language and ☆☆☆☆ :)
Je suis Charlie!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Regex: matching character which happens exactly once (using global memory)
by QM (Parson) on Oct 23, 2017 at 14:46 UTC | |
by LanX (Saint) on Oct 23, 2017 at 14:50 UTC | |
by QM (Parson) on Oct 23, 2017 at 16:57 UTC | |
by LanX (Saint) on Oct 23, 2017 at 18:51 UTC |