But it's less than elegant in the code. Everything has a prefix char, and here's one that has a postfix as well.
Consider how to simplify this regex:
That is, what I really want is/(^([$@*%]))|(^<.*>$)/
with the stipulation that the $3 is present only if $1 was <, and absent otherwise./^([$@*%<)(.*)(>?)$/
I can certainly do it in a line or 3, especially with lots of comments for clarity. But I'm wondering if there is a really cool way to do it in one succinct bite (wishing for grammars like Perl6 here...).
On a more meditative note, I see that a more powerful pattern engine can make things clearer simply because you can, in analogy with English, sum up your selection with a simple statement of intent, rather than groping for an adjective but having to speak at length about this and that special case.
I see this in documentation, too. If the rule is simple it not only makes the code simple, but makes the documentation easy too.
—John
In reply to conditional match in regex by John M. Dlugosz
For: | Use: | ||
& | & | ||
< | < | ||
> | > | ||
[ | [ | ||
] | ] |