开发者

removing unwanted text [duplicate]

This question al开发者_StackOverflowready has answers here: Closed 12 years ago.

Possible Duplicate:

removing unwanted text

I want to remove extra text:

test is like that www.abc.com dsfkf ldsf <info@abc.com>

I want to get only the email text in C#


Use

string textInBrackets = Regex.Match(yourText, "(?<=<)[^>]*(?=>)").ToString();


If you want to get all emails from text, you can try this:

List<string> foundMails = new List<string>();
string regex = "[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?";
string text = "some text mail@something.com some other mail test.simple@something.net text.";
Match m =  Regex.Match(text, regex);
while (m.Success)
{
     foundMails.Add(m.ToString());
     m = m.NextMatch();

}

foundMails collection contains found emails

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜