2

I am having trouble splitting a String using a regular expression

"[{'name':'abc','surname':'def'},{'name':'ghi','surname':'jkl'},{'name':'asdf','surname':'asdf'}]"

Now I'd like to split this to

"{'name':'abc','surname':'def'}" and "{'name':'ghi','surname':'jkl'}"

Later on I will deserialize both Strings and work with the values. I must admit that I've worked way too little with regular expressions and would love if someone could help me. I want to split by those square brackets as well as by the middle comma. I was either splitting by ALL commas or not splitting at all.

Kind regards

1 Answer 1

7

This Regex will do that:

({.*?})

and here is a Regex 101 to prove it.

To use it you might do something like this:

var match = Regex.Match(input, pattern);
// match.Groups has all of the matches
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks a lot. Regex 101 seems to be useful
@voskart, yeah Regex 101 is awesome for building Regex patterns. There are a lot of other tools out there, I just prefer that one.

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.