lilypond-user
[Top][All Lists]
Advanced

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

Re: notes regex expression


From: Gianmaria Lari
Subject: Re: notes regex expression
Date: Thu, 31 Aug 2017 18:20:57 +0200



On 31 August 2017 at 11:06, Gregrs <address@hidden> wrote:
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.

For the articulation is not a problem, at the moment I don't need it. I'm writing some c# classes to help me generating lilypond source files. The music I want to generate are technical exercises for accordion. I asked for the regex because I thought that maybe something already existed. Thanks a lot for you help!
 
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.

Not a problem. Your regex would be an excellent starting point. I rarely use regex so I'm not good with it.

If I will improve your regex, I will send them here so others can take advantage.
 
Hope they're useful though. You might find this site useful for trying things out: http://regex101.com

Yes, it's the site I use :) 

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 a lot Greg!!!!
Ciao, g. 

reply via email to

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