On Thu, 19 Mar 2020 13:18:58 -0000 (UTC)
Martin Gregorie wrote:
> I spent more time than I should have yesterday trying to understand
> regcomp(), regexec() and regerror() well enough to validate a string
> containing an e-mail address string to make sure that: its structure is
> correct and neither the username nor the domain contains characters they
> shouldn't.
The perl book on regular expressions includes one that validates
email addresses - it is extremely long (more than a page IIRC), they are
astonishingly difficult things to validate.
There's this site https://emailregex.com/ which has what purports
to be a good regex for the job:
(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:
[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\\
[\x01-\x09\x0b\x0c\x0e-\x7f])*")@(?:(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+
[a-z0-9](?:[a-z0-9-]*[a-z0-9])?|\[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9]
[0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-]*[a-z0-9]:(?:
[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\\
[\x01-\x09\x0b\x0c\x0e-\x7f])+)\])
You might need pcre (the perl compatible regex library).
--
Steve O'Hara-Smith | Directable Mirror Arrays
C:\>WIN | A better way to focus the sun
The computer obeys and wins. | licences available see
You lose and Bill collects. | http://www.sohara.org/
--- SoupGate-Win32 v1.05
* Origin: Agency HUB, Dunedin - New Zealand | FidoUsenet Gateway (3:770/3)
|