【问题标题】:removing unwanted text [duplicate]删除不需要的文本[重复]
【发布时间】:2010-07-01 01:55:50
【问题描述】:

可能重复:
removing unwanted text

我想删除多余的文字:

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

我只想获取 C# 中的电子邮件文本

【问题讨论】:

  • 如果您的示例中确实有一个电子邮件地址,这可能会更容易一些。
  • @Joel - 你编辑了电子邮件地址,我不知道为什么,这是一个完全有效的地址,你不知道它在括号中的原因或来源是什么。还原您的更改,因为在那之后问题就没有意义了。

标签: c# regex textbox


【解决方案1】:

使用

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

【讨论】:

    【解决方案2】:

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

    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 集合包含找到的电子邮件

    【讨论】:

      猜你喜欢
      • 2011-01-17
      • 1970-01-01
      • 1970-01-01
      • 2021-06-11
      • 2020-05-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多