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: Sven Axelsson
Subject: Re: Multiple replacements in one regular expression?
Date: Wed, 21 Jan 2015 14:45:35 +0100

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"

-- 
Sven Axelsson
++++++++++[>++++++++++>+++++++++++>++++++++++>++++++
>++++<<<<<-]>++++.+.++++.>+++++.>+.<<-.>>+.>++++.<<.
+++.>-.<<++.>>----.<++.>>>++++++.<<<<.>>++++.<----.



reply via email to

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