in reply to Re^5: Why my Regex doesn't work
in thread Why my Regex doesn't work

You can't do it in one pass without zero-width assertions of some kind, because the matches can't overlap. For instance,
'ABABABA' =~ /ABA/g; # only matches twice #^^^ ^^^ here and here # ^^^ not here
But I don't see any other zero-width assertions (besides lookarounds) that look like they would be helpful here. You can diddle with the match position outside of the regex engine to make it find overlapping matches. This matches three times:
$_ = 'ABABABA'; while (/ABA/g) { print pos($_), "\n"; pos($_)--; }
You're right, though, regexes aren't the solution for every problem. In particular, highly structured text (like HTML or program source code) can be difficult to manipulate with regexes alone.

Replies are listed 'Best First'.
Re^7: Why my Regex doesn't work
by choroba (Cardinal) on Apr 12, 2017 at 09:11 UTC
    Generally, you'd need
    pos($_) -= length($&) - 1;

    instead of subtracting 1, because the overlap could be longer. Tested with

    $_ = "AAAABAAAA"; while (/AAA/g) { ...
    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,