Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

Re^3: RegExp help

by JavaFan (Canon)
on Mar 27, 2012 at 09:06 UTC ( [id://961874]=note: print w/replies, xml ) Need Help??


in reply to Re^2: RegExp help
in thread RegExp help

There's little I can offer to make it more understandable: the syntax of email addresses is complex. Just be glad that we're living in a post-5.10 world: now we can use rules and recursion which allows us to, almost mechanically, translate BNF grammars to regular expressions. In one (both?) of the editions of "Mastering Regular Expressions", Jeffrey Friedl gives a pre-5.10 regular expression to match email addresses. That one is far, far more complex (and doesn't allow nested comments below a certain depth (2, IIRC)).

You may want to look at RFC 822, or one of its descendants, for the grammar of email addresses. It's my understanding, the regexp I gave was constructed based on the grammar given in one of the RFCs. (I don't recall which one, and the file t/re/reg_email.t doesn't say where it comes from).

Replies are listed 'Best First'.
Re^4: RegExp help
by heatblazer (Scribe) on Mar 27, 2012 at 14:17 UTC

    Well I am getting some tutorials now and trying to parse your previous example ( go easy on me tho :). From the beginning I`ve started with something simple as that (using a simple divide and conquer technique) :

    my $match; if ( $match = split(/\s/, 'somemail@yahu.com') == 1 ) { # do we have a whole string with no spaces in it? # if so check for '@' if ( $match = split("@", 'somemail@yahu.com') == 2 ) { # if it`s split by 2 then it must be 1 @ sign # then do some other nested checks # whith regex for validating mail ex. are there any # dots or hash signs in the end of domain etc. } } else { print "Mail verification form failed!\n"; # call back the mail form }

    Now I`ll keep going with regex to master it because I really want to know what is going on there and how.

      Well, one can have spaces in email addresses. For instance,
      "perl monks"@example.com
      is a syntactical correct email address.

        That`s new to me... Very strange to have a spaces in mail.. I`ll keep in mind that.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://961874]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (4)
As of 2024-04-18 04:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found