Sam K
Sam K

Reputation: 410

How to Split the string using Regex using c#?

I am trying to split the string using Regex and struck with a problem. Can someone help here

I have a string "The Quick <B> Brown fox <AB> Jumped on <Z>"

I want to return only B, AB, Z as strings.

Regex regex = new Regex(@"<(.*)>");

foreach (Match match in regex.Matches(strMessage))
 {
     MessageBox.Show(match.Value.ToString());
 }

but this returns only one message with

<B> Brown fox <AB> Jumped on <Z>

Upvotes: 0

Views: 30

Answers (1)

Hossein Badrnezhad
Hossein Badrnezhad

Reputation: 502

use from this regex instead of.

Regex regex = new Regex(@"[<](\w*)[>]");

foreach (Match match in regex.Matches(strMessage))
{
    MessageBox.Show(match.Value.ToString());
}

Upvotes: 1

Related Questions