Link to home
Start Free TrialLog in
Avatar of Chris Lane
Chris Lane

asked on

Separate email addresses with regular expression.

Hi,
I have written a regular expression to capture an email address from a specific zone on a page using a software application.
The application will then send a copy of the document to that email address.
I have come across two problems. First is that email addresses can contain numeric values as well as text. Problem solved by adding 0-9 in the regex.
Second issue is that some of the documents have more than one email address separated by / (forward slash).
Is there an easy way to find the / and stop returning any further email addresses?
The first address will always be the one I need.
Thanks in advance,
Chris.
Avatar of HainKurt
HainKurt
Flag of Canada image

just use this before regex

var email='abc@domain1.com / xyz@domain2.com';
var firstemail = email.split(" / ")[0]
alert(">" + firstemail +"<");

Open in new window


demo

https://jsfiddle.net/538oyfco/
Avatar of Chris Lane
Chris Lane

ASKER

That looks like it will do the trick. Thanks for the advice. Is there a simpler way to do it using the same regular expression?
I'm using regex buddy and it doesn't like the "/" at all!
use "\/"
I will try that now.
Thanks for your help.
Chris.
ASKER CERTIFIED SOLUTION
Avatar of Leonidas Dosas
Leonidas Dosas
Flag of Greece image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Thanks, Leonidas.
I will try that tomorrow on my VM and let you know if it works in my application.
Regards,
Chris.