2010-07-01 53 views
0

可能重复:
removing unwanted text除去不需要的文本

我想删除多余的文字:

test is like that www.abc.com dsfkf ldsf <[email protected]> 

我想只有在C#中的电子邮件文本

+0

如果您的示例中实际存在电子邮件地址,它可能会更容易一些。 – 2010-07-01 02:00:22

+1

@Joel - 你编辑了电子邮件地址,我不确定为什么,这是一个完全有效的地址,你不知道它是在括号里的原因还是源头是什么。恢复你的改变,因为这个问题在那之后毫无意义。 – 2010-07-01 02:13:41

+0

http://stackoverflow.com/questions/3154587/removing-unwanted-text的副本。请问一次 – 2010-07-01 02:22:47

回答

0

使用

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

如果你想从文本的所有电子邮件,你可以试试这个:

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 [email protected] some other mail [email protected] text."; 
Match m = Regex.Match(text, regex); 
while (m.Success) 
{ 
    foundMails.Add(m.ToString()); 
    m = m.NextMatch(); 

} 

foundMails集合包含发现电子邮件

相关问题