Hi again,
as a follow-up to my previous regex question I have another one: Can I
use regular expressions to apply multiple substitutions in one go?
The following code works and gives the desired result:
\version "2.19.16"
#(use-modules (ice-9 regex))
str = "This should be \partcombine & match everything"
#(set! str
(regexp-substitute/global #f "\\\\" str
'pre "\\textbackslash " 'post))
#(set! str
(regexp-substitute/global #f "&" str
'pre "\\&" 'post))
=> "This should be \textbackslash partcombine \& match everything"
However, this approach will get quite cumbersome (and expensive) when
there are numerous characters to be escaped. Therefore I'd like to know
if I can "fold" them in one regular expression substitution.
I know that I can capture different groups to match the different
characters to be escaped, and I know how regexp-substitue allows me to
re-insert the matches in the resulting string. But that's not what I want.
What I *do* want is:
- capture a number of expressions in capture groups
- replace each capture group with a matching replacement string.
One thing to note is that the order of operations matters. If I reverse
the order of the example then first the ampersand would be prepended
with the backslash and then this backslash would be escaped with its own
replacement string.
Somehow I don't seem to be able to find the solution myself :-(
TIA
Urs
_______________________________________________
lilypond-user mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/lilypond-user