Live data from Hacker News

I don't know Regex

ideasof.andersaberg.com

1–10 of 55 posts

Re: I don't know Regex

#2
Which one is the simplest? I rest my case.

Actually, I like neither. The code is easier to read, but the regex gives a broader overview. This is something where parser combinators can shine. E.g., from Haskell's email-validate:

  addrSpec = do
  	localPart 
Source: http://hackage.haskell.org/packages/archive/email-validate/1...

To end with a positive note: good work on the library! I think it will be useful for many people who dislike writing regexes.

Re: I don't know Regex

#4
His example could be simplified to

    ^ ( [a-z0-9]+ @ [a-z]+ \. [a-z]+ ) $
With ignore case and ignore whitespace mode on. I work with Regex a lot so I find this very readable, set in a universal format, and more concise. I will gladly concede that the builder would be easier for those that aren't familiar with regex.

Re: I don't know Regex

#5

Your email regex is wrong. There are some obscure email address that will not work. For example my.email domain+plus@some.weird3.com For more see http://en.wikipedia.org/wiki/Email_address#Valid_email_addre...

[deleted]

Re: I don't know Regex

#6

Your email regex is wrong. There are some obscure email address that will not work. For example my.email domain+plus@some.weird3.com For more see http://en.wikipedia.org/wiki/Email_address#Valid_email_addre...

apparently this is the correct fully rfc-compliant email validation regex:

http://www.ex-parrot.com/pdw/Mail-RFC822-Address.html

Re: I don't know Regex

#7

Your email regex is wrong. There are some obscure email address that will not work. For example my.email domain+plus@some.weird3.com For more see http://en.wikipedia.org/wiki/Email_address#Valid_email_addre...

> validates an email adress (something you should never do with Regex, because you won't get it right, but anyway)

I think it is clear that this isn't the point.

Re: I don't know Regex

#9
post #4

His example could be simplified to ^ ( [a-z0-9]+ @ [a-z]+ \. [a-z]+ ) $ With ignore case and ignore whitespace mode on. I work with Regex a lot so I find this very readable, set in a universal format, and more concise. I will gladly concede that the builder would be easier for those that aren't familiar with regex.

Thanks for the comments! I bet I could improve the way regex is generated, since i'm not so comfortable working with regex.

I'd also like to add features, a .Not operator would be really useful, and I'd gladly take a pull request if anyone have an implementation in mind :)

If I receive some signals that others find this library useful and would like me to add some feature, I'd be more than glad to do so.

Re: I don't know Regex

#10
I've been making good use of http://www.regexper.com/ since it was linked here. It's made learning regexes much easier as it gives a clear workflow diagram.

For example, it showed that the horrible email regex in this article had a couple of errors - the dot before the TLD should be escaped (without the escape, it's 'any character'), and that group #1 can either be letters or digits, but not both (when it can be).

It's still not a good regex, since there are characters like hyphens, dots, and pluses that are valid pre-'@' characters, which both sample regexes fail to recognise.

Post reply on HN