Reputation: 32104
I have the following string (the double quotes are part of the string):
"abc def ghi" "%1" "%2"
So the string starts with a double quote, each segment is separated by " "
and the string ends with a double quote again. I would like to split this into:
abc def ghi
%1
%2
I tried the following: "(^\")|(\" \")|(\"$)"
but that doesn't give me the desired result.
Upvotes: 0
Views: 4142
Reputation: 12776
Regex regex = new Regex("\"(.*?)\"");
Results:
http://rubular.com/r/lXbDIpkRRQ
Upvotes: 1
Reputation: 301157
Don't complicate it. Just use a string split:
string test = "\"abc def ghi\" \"%1\" \"%2\"";
var splits = test.Split(new string[]{"\" \"","\""},StringSplitOptions.RemoveEmptyEntries);
foreach (var split in splits)
{
Console.WriteLine(split);
}
( removes the superfluous / empty entries as well)
Upvotes: 3
Reputation: 14919
string s = "\"abc def ghi\" \"%1\" \"%2\"";
string[] splittedStrings = s.Split('"');
string a = splittedStrings[1];
string b = splittedStrings[3];
string c = splittedStrings[5];
Upvotes: 1