The basic idea is to use or conditions, which match first an escaped sequence, secondly a directive and then a single character.
With a /g modifier within a while condition the match will start where the last one ended.
Group only on your directives.
2 proofs of concept:
The second one w/o while loop.
Please notice that you need to check for defined, since every escape or single character is an empty (since ungrouped) match.
DB<120> $str='xxx@@xx\@xx@abc\@xxx@efg@\xxx' => "xxx\@\@xx\\\@xx\@abc\\\@xxx\@efg\@\\xxx" DB<121> print ( defined $1 ? "$1\t" : "") while ( $str =~ m/ (?: [\\ +\@]{2} | ( \@\w+ ) | . ) /xg ) @abc @efg DB<122> grep { defined } $str =~ m/ (?: [\\\@]{2} | ( \@\w+ ) | . ) +/xg => ("\@abc", "\@efg")
more efficient:
DB<135> grep {defined} $str =~ m/ (?: [\\\@]{2}+ | ( [\\\@]\w+ ) | [ +^\\\@]+ ) /xg => ("\@abc", "\@efg")
Cheers Rolf
( addicted to the Perl Programming Language)
In reply to Re: better way to escape escapes (updated)
by LanX
in thread better way to escape escapes
by RonW
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |