I'm using the followin RegEx which I found in this similar question:
/[^\s"]+|"[^"]*"/g
I want to split the string by spaces except when strings are quoted by double quotes. The quotes have to be included by the result.
This is my C# code:
MatchCollection conditions = Regex.Matches(strCondition, @"/[^\s""]+|""[^""]*""/g");
conditions.Count is always zero! When I test the regex online, it works!
Example input:
"0" MATCHES NOCASE "Den Bosch" OR "0" MATCHES NOCASE "'s Hertogenbosch"
"0" MATCHES "1" AND "1" MATCHES "2" AND "2" MATCHES "3" AND "3" MATCHES "4" AND "4" MATCHES "5"
What am I doing wrong? I wasted several hours and have no clue anymore.
This one: (?<=")\w[\w\s]*(?=")|\w+|"[\w\s]*"
does give results in my case, but does not give the desired result because it fails on single quotes.