lilypond-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Multiple replacements in one regular expression?


From: Urs Liska
Subject: Re: Multiple replacements in one regular expression?
Date: Wed, 21 Jan 2015 14:52:04 +0100
User-agent: Mozilla/5.0 (X11; Linux i686; rv:31.0) Gecko/20100101 Thunderbird/31.4.0


Am 21.01.2015 um 14:45 schrieb Sven Axelsson:
On 21 January 2015 at 14:01, Urs Liska <address@hidden> wrote:>
Hm, it's not as easy as that because the escaping can be quite different,
e.g.

"&" -> "\&"
"\" -> "\textbackslash"
"[" -> "{[}"

etc.

So what I really need is:
match (&)(\)([)
and replace that with
(\&)(\textbackslash )({})

And I would be glad if I wouldn't have to do that with individual runs of
regexp-substitute.
Looks like you can use a callback function with regexp-substitute and
then do whatever
necessary there, eg. (from the Guile manual).

(regexp-substitute/global #f "[a-z]+"  "to do and not-do"
   'pre (lambda (m) (string-reverse (match:substring m))) 'post)
⇒ "ot od dna ton-od"


That looks promising, and I think I can combine that with Johan's suggestion of an association list.

Thanks to both.
Urs



reply via email to

[Prev in Thread] Current Thread [Next in Thread]