Many flavors of regular expressions support comments now. You can make your regular expression a bit more readable by adding comments. Like in programming languages, where a comment does not change the behavior of the program, a regular expression comment does not change the behavior of the regular expression.
A regular expression comment is written like this: (?#comment) where comment can be any text, as long it is not ).
Here is an example of a regular expression for a simple email address: [A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,6}
And here is the same regular expression with a comment (bold): [A-Z0-9._%+-]+@(?#domain)[A-Z0-9.-]+\.[A-Z]{2,6}
Why am I posting this? Because I’m using this in my new Snort rules I’m blogging about soon.
I’ve often thought that it would be good to have a verbose regular expression language that was very readable. It should translate directly into the usual terse regex and vice-versa.
Comment by lseltzer — Friday 5 June 2015 @ 1:20
Actually, you can put comments in regex to make them more unreadable than they already are …
Comment by s — Friday 5 June 2015 @ 9:38
100% of the features can be abused …
Comment by Didier Stevens — Friday 5 June 2015 @ 16:34