I need some help to find a regex expression to extract user names from these emails: (Regex newbie here)
- john.stewartcompany1@example.com
- bruce.williamscompany1@example.com
- richard.weiss@example.com
- julia.palermocompany2@example.com
- edward.philipscompany3@example.com
As you can see from the emails, almost all of them have the company name following the name. (company1, company2, company3)
But some emails have no company inserted. (See richard.weiss) All of them will have @example.com
So I need to extract only the names, without the company, like this:
- john.stewart
- bruce.williams
- richard.weiss
- julia.palermo
- edward.philips
I've come up with this pattern so far:
/(.+)(?=@example.com)/g
This only solves half of the problem, as it keeps the company name in the names.
- john.stewartcompany1
- bruce.williamscompany1
- richard.weiss
- julia.palermocompany2
- edward.philipscompany3
I still need to remove the company names from the user names. Is there a way to accomplish this with a single regex pattern?
Any help appreciated.
PS: Thanks for the replies. I forgot to mention...
The company names are limited. We can safely assume from my example that there will be only company1, company2 and company3.
Thanks.