Live data from Hacker News

Regexper: Beautiful regexp visualizations

regexper.com

111–120 of 132 posts

Re: Regexper: Beautiful regexp visualizations

#111
post #105

Earlier quoted context omitted.

In general terms I absolutely agree with you. However, the subtleties might have more to do with ensuring that the intent of the transaction is adhered to rather than not. The first assumption is that your intent is to capture accurate user information and the user's intent is to give it to you. With that established, it is a good idea to apply sensible measures at your end in order to ensure that the data is accurat…

Is "jotdot@somedomain.com." actually invalid? My understanding is that something like "example.com." represents the same domain name as "example.com" does. I don't know if things work differently for email addresses, though.

I think you might be confusing absolute or rooted FQDNs (Fully Qualified Domain Name) and relative FQDNs (in the context of DNS) with valid or invalid email addresses.

An absolute FQDN ends with a period:

    apple.com.
A relative FQDN does not:

    apple.com
When a DNS resolver sees an absolute FQDN it has a pretty direct path to getting the corresponding IP address.

If, instead, the resolver is looking at a relative FQDN it does not, and it tries to fix it, and it could go around in circles for a while depending on where the resolver is running. What the resolver does is add different forms of DNS suffixes it has available until it either figures it out, fails or times out. For example, if the resolver is running on www.example.com, it might try the following:

    apple.com.www.example.com.
    apple.com.example.com.
    apple.com.com.
If it finds any CNAME records it will follow them and go around in circles some more. I ran across this recently while looking at the whole issue of email validation through DNS. So, this is fresh pain you are hearing about!

Here's my post on SO:

http://stackoverflow.com/questions/14065946/what-would-cause...

I also have a DNS function test page on one of my sites here:

http://www.tommyteaches.com/test/test2.php

If you try a domain like "notarealdomain1.com" you'll see that it takes a while (20 to 30 seconds per test) for the DNS functions to resolve it. If, instead, you enter "notarealdomain2.com." (period at the end) the DNS resolver will come back almost immediately. This is due to the DNS suffix append mechanism described above.

Note that if you enter the same name twice, the second test will return faster due to caching.

Here's an interesting read:

http://tools.ietf.org/html/rfc1535

Re: Regexper: Beautiful regexp visualizations

#112
post #98
post #73

it breaks with this: (?:(?:\r\n)?[ \t]) (?:(?:(?:[^() @,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t] )+|\Z|(?=[\["() @,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t])) "(?:(?: \r\n)?[ \t]) )(?:\.(?:(?:\r\n)?[ \t]) (?:[^() @,;:\\".\[\] \000-\031]+(?:(?:( ?:\r\n)?[ \t])+|\Z|(?=[\["() @,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t])) "(?:(?:\r\n)?[ \t]) )) @(?:(?:\r\n)?[ \t]) (?:[^() @,;:\\".\[\] \000-\0 31]+(?:(?:…

To anyone that sees this email validation regex, DO NOT USE IT. Hope that was clear, if not obvious. Use something like `^([^\s]*)@([^\s]*\.[^\s]*)$` which will do most of the work for you, then check second group for common domain typos, and what have you.

>Use something like `^([^\s]*)@([^\s]*\.[^\s]*)$` which will do most of the work for you

I don't understand. How does this expression do anything even remotely close to email validation?

For example, how does it tell you that:

    These are valid:
      test@nasa.gov
      ~~~~@nasa.gov
      joe+sometext@nasa.gov
      test@bbc.co.uk
and that:

    These are NOT valid
      test@example.com    (no MX RR)
      test@-nasa.gov
      test"@nasa.gov
      test@nasa.gov-
      test         
      test@nasa.rockets
      test@bbc.co..uk
      test@bbc.com.uk
      test@bbc.co.eu.uk
You'd have to write all the validation logic yourself all over again. And that's just a few examples.

Barring anything else, the RFC822 expression isn't so bad that someone should replace it with the kind of thing you are suggesting.

Sorry if I don't see it.

Re: Regexper: Beautiful regexp visualizations

#116
post #73

it breaks with this: (?:(?:\r\n)?[ \t]) (?:(?:(?:[^() @,;:\\".\[\] \000-\031]+(?:(?:(?:\r\n)?[ \t] )+|\Z|(?=[\["() @,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t])) "(?:(?: \r\n)?[ \t]) )(?:\.(?:(?:\r\n)?[ \t]) (?:[^() @,;:\\".\[\] \000-\031]+(?:(?:( ?:\r\n)?[ \t])+|\Z|(?=[\["() @,;:\\".\[\]]))|"(?:[^\"\r\\]|\\.|(?:(?:\r\n)?[ \t])) "(?:(?:\r\n)?[ \t]) )) @(?:(?:\r\n)?[ \t]) (?:[^() @,;:\\".\[\] \000-\0 31]+(?:(?:…

Also breaks with the expression to check whether a number is divisible by 7 from https://raw.github.com/matthiasgoergens/Div7/master/regex7 . Though perhaps because that expression is in grep style, and that may differ from Javascript style.

Re: Regexper: Beautiful regexp visualizations

#117
post #98

Earlier quoted context omitted.

To anyone that sees this email validation regex, DO NOT USE IT. Hope that was clear, if not obvious. Use something like `^([^\s]*)@([^\s]*\.[^\s]*)$` which will do most of the work for you, then check second group for common domain typos, and what have you.

>Use something like `^([^\s]*)@([^\s]*\.[^\s]*)$` which will do most of the work for you I don't understand. How does this expression do anything even remotely close to email validation? For example, how does it tell you that: These are valid: test@nasa.gov ~~~~@nasa.gov joe+sometext@nasa.gov test@bbc.co.uk and that: These are NOT valid test@example.com (no MX RR) test@-nasa.gov test"@nasa.gov test@nasa.gov- test tes…

Honestly I don't understand why people get all flustered over email validation, I would probably use something along the lines of this just to check that the email address is along the lines of name@domain.com, obviously this could do with a little tweaking.

The best way to validate an email address is to send an email to whatever address is supplied to you, if it is a true email address the user will receive an email and it will be validated, if not then their account or query will go unused/unanswered and that will be down to them.

Re: Regexper: Beautiful regexp visualizations

#118
post #92

Earlier quoted context omitted.

BTW, using this regex to validate email is a bad idea. For one thing, it doesn't cover RFC5322. The only right way to do it, as far as I am concerned, is state machine code that evaluates the address character by character as well as DNS.

It is probably acceptable in most cases to just use a trivial regex to match the most likely 99.9% of addresses. 'something@something.something', maybe checking that last something for some sanity. I mean, obviously unless you are writing an MTA or whatever.

> It is probably acceptable in most cases to just use a trivial regex to match the most likely 99.9% of addresses.

The more trivial the better (something like .[star]@.[star] ([star] == *, HN formatting bites sometimes)); people going too clever with validating e-mails (like if there was a good reason for doing that) end up rejecting + sign in the address as invalid, which is incredibly annoying for GMail users.

Re: Regexper: Beautiful regexp visualizations

#119

Earlier quoted context omitted.

I'd avoid it to prevent url encoding problems.

You could base64 it first.

With an effective maximum URL length of 2000 characters, you'd be stuck with a regex limit of around 1300 characters once you take into account the overhead of base64 encoding.
Post reply on HN