I am using the re module in Python(3) and want to substitute (re.sub(regex, replace, string)) a string in the following format
"foo <bar e word> f ga <foo b>"
to
"#foo <bar e word> #f #ga <foo b>"
or even
"#foo #<bar e word> #f #ga #<foo b>"
But I can't isolate single words from word boundaries within a <...> construct.
Help would be nice!
P.S 1
The whole story is a musical one: I have strings in the Lilypond format (or better, a subset of the very simple core format, just notes and durations) and want to convert them to python pairs int(duration),list(of pitch strings). Performance is not important so I can convert them back and forth, iterate with python lists, split strings and join them again etc. But for the above problem I did not found an answer.
Source String
"c'4 d8 < e' g' >16 fis'4 a,, <g, b'> c''1"
should result in
[
(4, ["c'"]),
(8, ["d"]),
(16, ["e'", "g'"]),
(4, ["fis'"]),
(0, ["a,,"]),
(0, ["g", "b'"]),
(1, ["c''"]),
]
the basic format is String+Number like so : e4 bes16
- List item
- the string can consist of multiple, at least one, [a-zA-Z] chars
- the string is followed by zero or more digits: e bes g4 c16
- the string is followed by zero or more ' or , (not combined): e' bes, f'''2 g,,4
- the string can be substituted by a list of strings, list limiters are <>: 4 The number comes behind the >, no space allowed
P.S. 2
The goal is NOT to create a Lilypond parser. Is it really just for very short snippets with no additional functionality, no extensions to insert notes. If this does not work I would go for another format (simplified) like ABC. So anything that has to do with Lilypond ("Run it trough lilypond, let it give out the music data in Scheme, parse that") or its toolchain is certainly NOT the answer to this question. The package is not even installed.