1

I have a large string that may have some items I want to retrieve out of it.

An example string could be

"The quick |Get Me|(header1) brown fox |Get Me|(info package) jumps over ..."

I would like a regex to extract what is in between the brackets, not including the brackets and the brackets will always follow "|Get Me|"

1 Answer 1

4

A pattern that will match:

\|Get Me\|\(([^)]+)\)

Usage:

var matches = Regex.Matches(myString, @"\|Get Me\|\(([^)]+)\)");

foreach(Match match in matches)
{
   var val = match.Groups[1].Value;
}
Sign up to request clarification or add additional context in comments.

4 Comments

+1 That does it, but just so Robert knows, it matches the whole |Get Me|(header1) string, and then you extract the header1 part using the matches' groups.
Yes that does do it, somehow and yes I needed to get a string out of a group collection. It's amazing and baffling thanks very much
@RobertHancliff - I suggest you read Mastering Regular Expressions. You will be much less baffled and start understanding regex to a good degree.
@RobertHancliff ... and experiment using the .NET Regex Tester at regexhero.net (personal non-affiliated recommendation)

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.