Inscrutability - use the `x` modifier and allow whitespace and comments, e.g.
/^(\\^+|_+|=)?([a-gA-G])(,+|'+)?(\\d*)(\\/)?(\\d*)$
becomes: /^
( \\^+ | _+ | = )? # sharps and flats
( [a-gA-G] ) # notes
( ,+ | '+ )?
( \\d* ) # duration
( \\/ )? # fractions
( \\d* ) # more duration? I'd need to read the spec
$/x
and use different delimiters to remove escaping of slashes: <^
( \\^+ | _+ | = )? # sharps and flats
( [a-gA-G] ) # notes
( ,+ | '+ )?
( \\d* ) # duration
( / )? # fractions
( \\d* ) # more duration? I'd need to read the spec
$>x
That's already much more readable, but then we have complaint number 2, composability. If you language supports it then use interpolation: SHARPS_AND_FLATS = /\\^+ | _+ | =/x
NOTES = /[a-g]/i
<^
(#{SHARPS_AND_FLATS})? # sharps and flats
(#{NOTES}) # notes
( ,+ | '+ )?
( \\d* ) # duration
( / )? # fractions
( \\d* ) # more duration? I'd need to read the spec
$>x
You see how it could go on. I'm not saying regex are always the right solution and not all languages have access to the same tools but there's often a lot that can be done to mitigate the awfulness (and a lot more here, lookarounds, named captures etc).The `x` modifier is the #1 fix, I never write anything above the most simple regex without it, and for the life of me I can't understand why it's hardly ever used.