Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Any regex pros for a tiny problem?
Message
From
09/09/2006 13:12:10
 
 
To
08/09/2006 20:29:48
Keith Payne
Technical Marketing Solutions
Florida, United States
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Miscellaneous
Thread ID:
01152495
Message ID:
01152554
Views:
26
This message has been marked as the solution to the initial question of the thread.
>Howdy!
>
>I'm having some trouble coming up with a regex matching expression for a small string format:
>
>C3#:4.
>-or-
>F4-:16t
>-or-
>E2b
>
>
>These represent musical notes.
>
>"C" is the base note (A - G, uppercase only).
>"3" is the octave (1 - 6).
>"#" is the accidental (optional: can be "#" sharp, "b" flat, "-" natural, or "" omitted).
>":" is required if anything follows...
>"4" is the duration (1 whole, 2 half, 4 quarter, 8 eighth, 16 sixteenth, 32 thirtysecond)
>"." is the duration modifier (optional: can be "." dotted, "t" triplet, or "" omitted)
>
>So the first char must be [A-G] and the second char must be [1-6]. After this it gets a little hairy. The accidental is optional, so it's possible to have the colon immediately follow the octave digit. If there is a colon, then there must be a duration digit and there cannot be a duration modifier without a duration digit.
>
>Thanks!

Keith,

No testing, but have a go at this
^([A-G][1-6][-#b]?(:(1|2|4|8|16|32)[.t]?)?)$
Gregory
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform