|
From: | Aaron Hill |
Subject: | Re: Regexp Functions |
Date: | Tue, 16 Jun 2020 01:41:46 -0700 |
User-agent: | Roundcube Webmail/1.4.2 |
On 2020-06-15 11:16 pm, Freeman Gilmore wrote:
"y" could represent one of my accidentals, "-y" inverted. "-ax3" , one of my accidentals , "-a" used 3 times; like a flag, but needs to be inverted to "-x3"."+rx2" needs a space like "+r x2". "t" standard accidental. All "+" removed. "-y -ax3 +rx2 -stx2 t" becomes "-y -a -x3 r x2 -st -x2 t" , then convert to list("-y" "-a" "-x3" "r" "x2" "-st" "-x2" "t").
This is sounding much more like you have invented a language/grammar that needs to be parsed rather than simply wanting to apply some arbitrary text transformation. The interest in string manipulation stems from wanting to support a form of shorthand within the microtonal ligature notation.
To that end, allow me to present an alternate way to attack the problem. Consider:
;;;; (apply append (map (lambda (m) (let ((inv (or (match:substring m 2) ""))) (map (lambda (s) (string-append inv s)) (filter (lambda (s) (not (string-null? s))) (map (lambda (n) (or (match:substring m n) "")) '(3 4)))))) (list-matches "((-)|\\+?)([a-z]*)(x[0-9]+)?" "-y -ax3 +rx2 -stx2 t"))) ;;;; ==== ("-y" "-a" "-x3" "r" "x2" "-st" "-x2" "t") ====Several assumptions are being made within the core regular expression above; but what is important to note is that we are not doing any text substitution of the original input. Rather, we are using a regular expression to identify the valid "words" and extract the key parts of those words. While you can certainly act upon the information right away, I am showing a way to build a list of strings that should meet your specification.
-- Aaron Hill
[Prev in Thread] | Current Thread | [Next in Thread] |