Regex excluding catches that ending with a dot
Regex excluding catches that ending with a dot
First of all, I don't need full e-mail address validation, my given task doesn't require it. I just want to upgrade my current regex code so that it won't match addresses ending with a dot.
My current code: [0-9A-Za-z.]+[@][0-9A-Za-z.]+
[0-9A-Za-z.]+[@][0-9A-Za-z.]+
It catches both "user@exampe.com", "user@example.com."
user@exampe.com
user@example.com
I'd like it to catch only from the string that ends without the dot. user@exampe.com
user@exampe.com
Example string:
dasd.fas@fsaf.dfas.dsa, zghs@gas.gsq, adg32.dsa12@cas, ksak@c.csa., gs32.basaa@scaa.upc.
dasd.fas@fsaf.dfas.dsa
zghs@gas.gsq
adg32.dsa12@cas
I'd like to catch the strings marked as code in the example.
Edit: I have only one line with multiple e-mail addresses separated with a , and a space after them.
,
space
[^.]$
Try
^YOUR-REb$– revo
Sep 9 '18 at 4:03
^YOUR-REb$
@ssieightynine, what is the character/sring between each email strings? tell us what is the whole input string is exactly.
– The Scientific Method
Sep 9 '18 at 6:40
Please specify a language or tool.
– revo
Sep 9 '18 at 8:20
4 Answers
4
You might add [0-9A-Za-z]after your regex to end with what you want to match in your character class without the dot followed by a positive lookahead (?=, |$) that asserts what follows is either a comma followed by a whitespace or the end of the string.
[0-9A-Za-z]
(?=, |$)
[0-9A-Za-z.]+@[0-9A-Za-z.]+[0-9A-Za-z](?=, |$)
[0-9A-Za-z.]+@[0-9A-Za-z.]+[0-9A-Za-z](?=, |$)
Regex Demo
([0-9A-z.]+@(?:.?[0-9A-z]+)+)(?=,|$)
([0-9A-z.]+@(?:.?[0-9A-z]+)+)(?=,|$)
Doesn't work if the last string doesn't end in a
.– Nick
Sep 9 '18 at 5:26
.
Fixed the problem
– Adam
Sep 9 '18 at 5:44
Just slightly modify your pattern: [0-9A-Za-z.]+[@](?:[a-zA-Z]|.(?=[a-zA-Z]))+.
[0-9A-Za-z.]+[@](?:[a-zA-Z]|.(?=[a-zA-Z]))+
It uses alternation after @ to match one or more: letters OR dot, if it's followed by another letter, thanks to positive lookahead: .(?=[a-zA-Z]).
@
.(?=[a-zA-Z])
Demo
Try this one:
just capture , , $ and group them in non-capturing group except end .
,
$
.
[0-9A-Za-z.]+[@][0-9A-Za-z.]+[0-9A-Za-z](?:(,|$))
demo here
Please read the whole question more carefully.
– sasieightynine
Sep 9 '18 at 6:09
@sasieightynine upated try it now
– The Scientific Method
Sep 9 '18 at 7:00
Thanks for contributing an answer to Stack Overflow!
But avoid …
To learn more, see our tips on writing great answers.
Required, but never shown
Required, but never shown
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
End with
[^.]$?– CertainPerformance
Sep 9 '18 at 3:59