RonW has asked for the wisdom of the Perl Monks concerning the following question:
I am processing an input format that can use either @ or \ to introduce inline directives. when a literal @ or \ is in the input, either character can be used to escape either character. IE: @@ or \@ or \\ or @\
Currently, I replace the escape sequences with place holders, then extract directives, then replace the placeholders with the intended literal occurrences of @ and \ in the string.
s/(?<![\\\@])[\\\@]\@/\x11/g; s/(?<![\\\@])[\\\@]\\/\x12/g; while (/[\\\@]([_A-Za-z]+)/) { print "Extracted code '$1'\n"; s/[\\\@]$1//; } s/\x11/\@/g; s/\x12/\\/g;
I'm sure there's a better way, but my search-foo is lacking. And so is my regex-foo. (And there's likely an input file that will break this.)
(and no, it's not LaTeX, despite the similarities)
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: better way to escape escapes (1 pass)
by tye (Sage) on Apr 16, 2014 at 01:42 UTC | |
Re: better way to escape escapes
by kcott (Archbishop) on Apr 16, 2014 at 03:00 UTC | |
Re: better way to escape escapes (updated)
by LanX (Saint) on Apr 16, 2014 at 01:09 UTC | |
Re: better way to escape escapes
by andal (Hermit) on Apr 16, 2014 at 09:23 UTC | |
by RonW (Parson) on Apr 16, 2014 at 14:50 UTC | |
by RonW (Parson) on Apr 16, 2014 at 16:06 UTC | |
Re: better way to escape escapes
by Anonymous Monk on Apr 16, 2014 at 00:11 UTC |
Back to
Seekers of Perl Wisdom