0

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#

Community
  • 1
  • 1
azeem
  • 1
  • It might be a little easier if there were actually an e-mail address in your sample. – Joel Coehoorn Jul 01 '10 at 02:00
  • 1
    @Joel - You edited out the email address, I'm not sure why, that was a perfectly valid address, you don't know the reason it was in brackets or what the source was. Reverting your change, since the question makes no sense after that. – Nick Craver Jul 01 '10 at 02:13
  • Duplicate of http://stackoverflow.com/questions/3154587/removing-unwanted-text. Please ask once – Philip Rieck Jul 01 '10 at 02:22

2 Answers2

0

Use

string textInBrackets = Regex.Match(yourText, "(?<=<)[^>]*(?=>)").ToString();
Jens
  • 25,229
  • 9
  • 75
  • 117
0

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

Iale
  • 678
  • 10
  • 24