I’m trying to code a RegEx that will extract e-mails that come in many forms:
user@domain.com , user@sub.domain.com, user at domain dot com, user (at) domain dot com
Here is my shot (naive I know):
(\w+)\s*(?:@?|(at)?|(\s*at\s*)?|(\(at\))?)\s*(\w+(?:\.|\s*dot\s*)){1,}com
Thats matches what I want but it also matches URLs. How to exclude URLs matching?
Consider this element:
The short answer is that you have too many
?s, such that a completely empty string will match several of them, such that no(at),@oratis necessary to match at all.Because you’re already separating the branches with
|s, you don’t need the?s to mark an individual branch as unnecessary — only one of them needs to match, but that one should be non-optional.