I have some characters in a string. I would like to find all email addresses from this string and find index also.
mytext= "My mail id is grk@gmail.com and my friend mail id is newxyz@yahoo.com";
Regex regex = new Regex(@"^[\w-\.]+@([\w-]+\.)+[\w-]{2,4}$ ");
Match match = regex.Match(mytext);
if (match.Success) {
TextBox1.Text = match.Value;
int IndexValue=match.Index;
}
match = match.NextMatch();
if (match.Success) {
TextBox2.Text = match.Value;
int IndexValue=match.Index;
}
This works...
Please refer to http://emailregex.com/ for more details.
Try following code snippet. Regex taken from