[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: notes regex expression
From: |
Gregrs |
Subject: |
Re: notes regex expression |
Date: |
Thu, 31 Aug 2017 10:06:25 +0100 |
User-agent: |
Mutt/1.8.3 (2017-05-23) |
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]*)(?=( |$))
Thanks,
Greg
--
Twitter: @gregrs_uk
PGP key ID: 64907C8A
Fingerprint: EBD1 077F CCDD 841E A505 3FAA D2E8 592E 6490 7C8A
signature.asc
Description: PGP signature