3 ms·
I'm not totally convinced by these English-like regex languages. Regex itself seems like a reasonable language: [a-z] means a to z x* means 0 or more xs ...
by dash2 5y ago
I'm not totally convinced by these English-like regex languages. Regex itself seems like a reasonable language:
[a-z] means a to z
x* means 0 or more xs
...
The problem is that
a) whitespace is significant, so long regexes start to become unreadable
b) no easy way to nest regexes
Perl 6/Raku seemed to solve this by making whitespace meaningless by default and allowing regexes to be nested into other regexes or entire "grammars".
- lf-non 5y agoCompletely agree. For js, xregexp [1] is a really nice long standing library that brings in these kind of enhancements and makes regular expressions a lot more readable. [1] https://xregexp.com https://xregexp.com
- amenod 5y agoThis. Also, I try to: - use only those regex features that are cross-platform (cross-engine?) - avoid `\w` and similar (what is word?) and instead use explicit rules (`[a-zA-Z]+`) - use [] instead of backslashes when escaping (`[(]` instead of `\(`) - especially useful with double/triple escaping - never use long regexes (there is always a better way) I never understood why people are afraid of regular expressions. That said, there are some performance/security implications wrt. backtracking that one should be aware of [0]. [0] https://javascript.info/regexp-catastrophic-backtracking https://javascript.info/regexp-catastrophic-backtracking
- fiddlerwoaroof 5y ago\w and “<“ and “>” are useful in regular expressions for programming source code because you can define them to match the character set of the programming language’s identifiers.
- valenterry 5y ago> avoid `\w` and similar (what is word?) and instead use explicit rules (`[a-zA-Z]+`) I don't think that's a good idea. What about Chinese, Japanese, Arabic, ...?
- CJefferson 5y agoMy personal irritation is I often want thing like [],() or + as the thing I'm searching for, and then after escaping things get really unreadable.