|
From: | Gianmaria Lari |
Subject: | Re: notes regex expression |
Date: | Thu, 31 Aug 2017 18:20:57 +0200 |
Hi Gianmaria,
On Wed, Aug 30, 2017 at 09:58:52PM +0100, Gregrs wrote:
The below _expression_ (minus the quotation marks) seems to work for notes and chords without any articulation etc. attached. I've used Vim regex syntax so \@<= is a positive lookbehind to match the space before it and address@hidden is a positive lookahead to match the space before it. It also selects the whitespace in between and after notes/chords.
' \@<=<*\([a-g][',]*[1-8]* *\)\+>* address@hidden *'
I constructed the above _expression_ in a hurry and forgot about accidentals.
I've put together a few more expressions below that might be useful (using the Italian accidentals language) in a couple of regex flavours: Vim and Python (which I think is used by Frescobaldi, for example). They still don't match any attached articulation etc.
Without getting more complex, some of the expressions will match things in a LilyPond source file that aren't notes, such as words in a markup that look like they could be notes. Also if you're trying to verify that matches are in fact valid notes, you might want to be a bit more strict than I have been e.g. with possible durations.
Hope they're useful though. You might find this site useful for trying things out: http://regex101.com
Notes
Vim: [a-g]\([ie]s\)\{0,2}[',]*[1-8]*
Python: [a-g]([ie]s){0,2}[',]*[1-8]*
Notes bordered by space or beginning/end of line
Vim: \( \|^\)\@<=[a-g]\([ie]s\)\{0,2}[',]*[1-8]*\( \|$\)address@hidden
Python: ((?<= )|(?<=^))[a-g]([ie]s){0,2}[',]*[1-8]*(?=( |$))
Chords
Vim: <\([a-g]\([ie]s\)\{0,2}[',]* *\)\+>[1-8]*
Python: <([a-g]([ie]s){0,2}[',]* *)+>[1-8]*
Chords bordered by space or beginning/end of line
Vim: \( \|^\)\@<=<\([a-g]\([ie]s\)\{0,2}[',]* *\)\+>[1-8]*\( \|$\)address@hidden
Python: ((?<= )|(?<=^))<([a-g]([ie]s){0,2}[',]* *)+>[1-8]*(?=( |$))
Notes or chords bordered by space or beginning/end of line
Vim: \( \|^\)\@<=\([a-g]\([ie]s\)\{0,2}[',]*[1-8]*\|<\([a-g]\([ie]s\ )\{0,2}[',]* *\)\+>[1-8]*\)\( \|$\)address@hidden
Python: ((?<= )|(?<=^))([a-g]([ie]s){0,2}[',]*[1-8]*|<([a-g]([ie]s){0,2}[' ,]* *)+>[1-8]*)(?=( |$))
[Prev in Thread] | Current Thread | [Next in Thread] |