Live data from Hacker News

You Should Learn Regex

blog.patricktriest.com

1–10 of 57 posts

Re: You Should Learn Regex

#4
A very extensive article, and it shows how powerful RXes are.

It makes a point, in "8.3 - For Problems That Don't Require Regex" that RXes should not be overused when a simpler solution exists.

But there are also problems that are better solved without RXes, but with a "parser" instead. The article mentions parsers, fails to mention that self-made parsers also provide solutions in the same problem space as RXes. Some communities (like the Haskell community) prefer parsers as they allow to be inspected, tested and typed. Parsers provide a more robust and hackable solution, that is possibly faster than the equivalent RX.

Here a short tutorial for a popular parser library in Haskell, to get an idea of what it's like:

http://akashagrawal.me/beginners-guide-to-megaparsec

Re: You Should Learn Regex

#5

> From validating email addresses Guys, no. Send an email. https://davidcel.is/posts/stop-validating-email-addresses-wi...

That works if you have content that you know is an email address.

If you have free-form content, and need to identify email addresses in it, then you can’t just email every subset of that text.

Re: You Should Learn Regex

#6

> From validating email addresses Guys, no. Send an email. https://davidcel.is/posts/stop-validating-email-addresses-wi...

Depends on the use case. For forms, a preliminary sanity check doesn't hurt, e.g. when the user enters their username and password, instead of email & password (accepting either would be best, but you can't always do that).

Re: You Should Learn Regex

#8
post #5

> From validating email addresses Guys, no. Send an email. https://davidcel.is/posts/stop-validating-email-addresses-wi...

That works if you have content that you know is an email address. If you have free-form content, and need to identify email addresses in it, then you can’t just email every subset of that text.

> That works if you have content that you know is an email address.

That's what validation is. You're talking about finding email addresses, which I agree that regex is relatively OK at doing, but there are still lots of edge cases in the spec that are irregular.

Re: You Should Learn Regex

#10
post #6

> From validating email addresses Guys, no. Send an email. https://davidcel.is/posts/stop-validating-email-addresses-wi...

Depends on the use case. For forms, a preliminary sanity check doesn't hurt, e.g. when the user enters their username and password, instead of email & password (accepting either would be best, but you can't always do that).

[deleted]
Post reply on HN