I am splitting a string
with regex using its Split()
method.
var splitRegex = new Regex(@"[\s|{]");
string input = "/Tests/ShowMessage { 'Text': 'foo' }";
//second version of the input:
//string input = "/Tests/ShowMessage{ 'Text': 'foo' }";
string[] splittedText = splitRegex.Split(input, 2);
The string
is just a sample pattern of the input. There are two different structures of input
, once with a space before the {
or without the space. I want to split the input
on the {
bracket in order to get the following result:
- /Tests/ShowMessage
- { 'Text': 'foo' }
If there is a space, the string gets splitted there (space gets removed) and i get my desired result. But if there isnt a space i split the string on the {
, so the {
gets removed, what i dont want though. How can i use Regex.Split()
without removing the split condition character?