3 ms·
I like how the marquee example is of how to do something you shouldn't be trying to do [1] anyway. In more general terms, if a regex is complicated enough that
by throwanem 10y ago
I like how the marquee example is of how to do something you shouldn't be trying to do [1] anyway.
In more general terms, if a regex is complicated enough that something like this seems to make sense, the problem is that your regex is too complicated, and you should fix that.
[1] https://news.ycombinator.com/item?id=12312574 https://news.ycombinator.com/item?id=12312574
- duaneb 10y ago> In more general terms, if a regex is complicated enough that something like this seems to make sense, the problem is that your regex is too complicated, and you should fix that. I disagree. There is no such thing as a "complicated regex" in itself; it's all the same to the underlying engine. It's the maintenance of the regex that's the problem. You could, for instance, compile many small, maintainable patterns into a (technically) complicated regex with guarantees it will evaluate as expected—which is one possible way the outlined SQL approach could work. Don't confuse process with technology.
- throwanem 10y ago> it's all the same to the underlying engine So what you're saying is that as long as I have a PCRE library linked into my brain, there's no problem. Gotcha.
- qwertyuiop924 10y agoGood point. With PEG, YACC/LEX clones, and tutorials online, it's not to hard to get a functional (if primitive) Real Parser nowadays.
- proactivesvcs 10y agoIt's my observation that a lot of problems people have with regex is that they haven't learned tips like "Is regex the right way to do this?", "Can I simplify this regex because I trust the input?" and "What do I really need the regex to do?". To validate a user-supplied email address, you arguably just need something along the lines of ^.@.\..$ to help avoid whitespace and forgetting the @ sign. In a lot of cases, if the email address is wrong, all that happens is either a) user login fails or b) user registration fails. Hence there's no need for unreadably-complex regex to validate.
- tempodox 10y ago“And now, you have two problems”.