4 ms·
> On the other hand, there are so many additions to the core formal language, like backtracking or Larry Wall knows what, that syntax has become cryptic. I'm n
by mikegerwitz 10y ago
> On the other hand, there are so many additions to the core formal language, like backtracking or Larry Wall knows what, that syntax has become cryptic.
I'm not going to argue with that, though languages like Perl (which have extended regular expressions so much that they're not actually regular expressions anymore) also allow named groups, for example.
I'm not arguing that certain circumstances aren't difficult to understand. In such cases, I do actually compose expressions from separate ones (e.g. variables): but they're still a concise syntax.
> (e.g. emacs regexes with four backslashes in a row).
Yes, such cases are unfortunate and confusing.
> I prefer to read actual words, so the following is fine for me:
For me, that took much longer to parse mentally than the equivalent regex. Or, if you're okay with minor changes and a proper locale:
/\b[\w.%+-]+@[\w\d.-]+\.[A-Z]{2,}\b/
I suspect that someone used to reading the notation you provided would have opposite results than I do. The reason I find the actual formal notation for the regex easier is because there's less to keep in memory---all the verbose extras that I have to strip out when forming my mental image of the regex.
If the regular expression were more complicated, the solution you presented might not be so bad. I would normally format it like this (if we stick with the verbose character classes):
/\b
[A-Z0-9._%+-]+
@
[A-Z0-9._-]+
\.
[A-Z]{2,}
\b
/
- mikegerwitz 10y agoAh, that didn't format well at all. I intended for this to display: / \b [A-Z0-9._%+-]+ @ [A-Z0-9._-]+ \. [A-Z]{2,} \b /