by Mark
26. June 2008 04:46
For a project I need te get the email adresses out of a string with all kinds of text in it. After a lot of trying I found the matchhandler method. It is quite easy, you just need to adjust the Replace command and add a MatchEvaluator. Then you can use the matchhandler to do anything with the right string. In this case I´m adding it to a generic list.
Regex.Replace(source, @"([a-zA-Z_0-9.-]+\@[a-zA-Z_0-9.-]+\.\w+)", new MatchEvaluator(MatchHandler));
And add the string to the generic list.
private string MatchHandler(Match m)
{
col.Add(m.Value);
return m.Value;
}
1296a943-b56d-4888-b714-7bcfeb0f1bb2|0|.0
Tags:
ASP.Net