lilypond-user
[Top][All Lists]
Advanced

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

Re: More Regexp help


From: Aaron Hill
Subject: Re: More Regexp help
Date: Sun, 28 Jun 2020 02:00:24 -0700
User-agent: Roundcube Webmail/1.4.2

Sorry. I included the wrong version of the code, before I had reduced/simplified some of the regular expressions. See changes below:

On 2020-06-27 10:04 pm, Aaron Hill wrote:
-----------------------------------------------------
Broken into individual steps, as you have requested:

;;;;
(use-modules (ice-9 regex))

(define string "a bx3 cd -jk -DRx2 rtyu -HJK 31 17x4 -7 -41x3")
(format #t "\n[1] ~s" string)

(set! string
  (regexp-substitute/global #f
    "(^|\\s)(-?)([0-9]+)"
    string
    'pre 1 2 "n" 3 'post))
(format #t "\n[2] ~s" string)

(set! string
  (regexp-substitute/global #f
    "((^|\\s)-?)([0-9]+)"
    string
    'pre 1 "n" 3 'post))


(set! string
  (regexp-substitute/global #f
    "(^|\\s)(\\S+)(x([0-9]+))"
    string
    'pre 1 "(* " 2 " " 4 ")" 'post))
(set! string (string-append "(" string ")"))
(format #t "\n[3] ~s" string)

(set! string
  (regexp-substitute/global #f
    "(\\S+)x([0-9]+)"
    string
    'pre "(* " 1 " " 2 ")" 'post))


(define expr (with-input-from-string string read))
(format #t "\n[4] ~s" expr)
;;;;
====
[1] "a bx3 cd -jk -DRx2 rtyu -HJK 31 17x4 -7 -41x3"
[2] "a bx3 cd -jk -DRx2 rtyu -HJK n31 n17x4 -n7 -n41x3"
[3] "(a (* b 3) cd -jk (* -DR 2) rtyu -HJK n31 (* n17 4) -n7 (* -n41 3))"
[4] (a (* b 3) cd -jk (* -DR 2) rtyu -HJK n31 (* n17 4) -n7 (* -n41 3))
====


-- Aaron Hill



reply via email to

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