Click here to Skip to main content
15,893,588 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi now is there any one want to help me to do it?
I want get all email adress in a string in reg expression. Could you give me an example?
Thanks!
Posted

Have a look at this[^] article.
 
Share this answer
 
Definitely you need to use Ragex pattern matching with that.

consider this Email Regex pattern.

[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}

take a look at my sample.

C#
ArrayList list = new ArrayList();
        string TestString = "From: Mabel Garcia <mabel@flossresearch.com> From: Mabel Garcia <mabel@flossresearch.com> From: mabel@flossresearch.com From: mabel@flossresearch.com (Mabel Garcia)";
        string regexPattern = @"[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}";
        Regex regex = new Regex(regexPattern);
        foreach(Match match in regex.Matches(TestString))
        {
            if (!list.Contains(match.Value))
                list.Add(match.Value);
        }



Please vote and Accept Answer if it Helped.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900