3 ms·
My attempt at the Perl 6 version of the example: rx:i/^^ [ <+ alpha + digit + [._%+-] >+ ] ** 2 % '@' '.' <alpha>** 2..* $$/ Notice that t
by grondilu 10y ago
My attempt at the Perl 6 version of the example:
rx:i/^^
[ <+ alpha + digit + [._%+-] >+ ] ** 2 % '@'
'.'
<alpha>** 2..*
$$/
Notice that this avoids the repetition of a pattern.
Of course, it'd make much more sense to write a grammar:
grammar Email {
token TOP { <name> '@' <domain> }
token name { <valid_char>+ }
token domain { <valid_char>+ '.' <alpha>** 2..* }
token valid_char { <alpha> | <digit> | <[._%+-]> }
}
- labster 10y agoPretty good, though <domain> should end with <alpha> 2..* Note that your version is not actually the same, as it accepts all alphabetic characters, not just ASCII ones. Which put it much closer to RFC 6532, but still not exactly there due to the quoting rules in usernames. Which get pretty hairy. See [1] for an implementation of RFC 822, which is a simpler version of the modern standard, for a regex to validate email in Perl 5. [1]: https://metacpan.org/source/RJBS/Email-Valid-1.200/lib/Email/Valid.pm#L390 https://metacpan.org/source/RJBS/Email-Valid-1.200/lib/Email... trigger warning: bleeding eyes