TIP: Click on subject to list as thread! ANSI
echo: rberrypi
to: MARTIN GREGORIE
from: HEAP O`TROUBLE
date: 2020-03-19 12:52:00
subject: Re: Regexes and C

On March 19, 2020 09:18, 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 upshot was that I couldn't do it because I could not write a regex
[snip]
> So, can any of you do better, i.e. write a regex that CAN validate the
> syntax of an e-mail address in terms of its structure and the set of
> permitted characters on the username and domain parts (the permitted
> character sets are not the same).
[snip]

1) To anchor a regex, use the '^' and '$' metacharacters. '^' matches the
empty string at the start of a line, and '$' matches the empty string at the
end of the line.

2) There is no regex that can validate email addresses with 100% certainty.
You /can/ write a regex that will come close, but there will be valid
outliers that your regex will call invalid.

3) The RFCs describe exactly what an email address can consist of. You want
to study, at least, RFC 5322 section 3.4
(https://tools.ietf.org/html/rfc5322#section-3.4)

HTH
--
Lew Pitcher
"In Skills, We Trust"

--- SoupGate-Win32 v1.05
* Origin: Agency HUB, Dunedin - New Zealand | FidoUsenet Gateway (3:770/3)

SOURCE: echomail via QWK@docsplace.org

Email questions or comments to sysop@ipingthereforeiam.com
All parts of this website painstakingly hand-crafted in the U.S.A.!
IPTIA BBS/MUD/Terminal/Game Server List, © 2025 IPTIA Consulting™.