Regexp separator string

I want to split a string in C # that looks like

a: b: "c: d"

so that the resulting array has

Array [0] = "a"

Array [1] = "b"

Array [2] = "c: d"

what regular expression is used to achieve the desired result.

Many thanks

+5
source share
2 answers

If the colon separator is separated by a space, you can use \ s to match the space:

string example = "a : b : \"c:d\"";
string[] splits = Regex.Split(example, @"\s:\s");
+4
source

This seems to work in RegexBuddy for me

(\w+)\s:\s(\w+)\s:\s"(\w+:\w+)"

input

a: b: "c: d"

mapped groups

  • a
  • b
  • c: d

, . . \w, \s .. , !

+1

All Articles