0

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>

1 Answer 1

1

use from this regex instead of.

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

foreach (Match match in regex.Matches(strMessage))
{
    MessageBox.Show(match.Value.ToString());
}
Sign up to request clarification or add additional context in comments.

1 Comment

You probably want (\w?) rather than (\w.). I believe it processes faster an it better expresses what you want

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.