Hi, I want to split a string in C# that looks like
a : b : "c:d"
so that the resultant array will have
Array[0] = "a"
Array[1] = "b"
Array[2] = "c:d"
what regexp do I use to achieve the required result.
Many Thanks
Hi, I want to split a string in C# that looks like
a : b : "c:d"
so that the resultant array will have
Array[0] = "a"
Array[1] = "b"
Array[2] = "c:d"
what regexp do I use to achieve the required result.
Many Thanks
This seems to work in RegexBuddy for me
(\w+)\s:\s(\w+)\s:\s"(\w+:\w+)"
input
a : b : "c:d"
matched groups
- a
- b
- c:d
As always be careful and understand what the regex actually does. Don't just copy blindly. This matches word characters \w, spaces \s, etc. Consider what data your input will actually have in it!
If the delimiter colon is separated by whitespace, you can use \s to match the whitespace:
string example = "a : b : \"c:d\"";
string[] splits = Regex.Split(example, @"\s:\s");