开发者

removing unwanted text [duplicate]

开发者 https://www.devze.com 2023-01-05 12:51 出处:网络
This question al开发者_StackOverflowready has answers here: Closed 12 years ago. Possible 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

精彩评论

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