1

Possible Duplicate:
Regular Expression to split on spaces unless in quotes

I need to split a specified string at all spaces in order to get arguments, however, I need all the text inside quotes to stay "un-split". For example:

ab "c d"

This needs to be split into 2 strings: 1. ab, 2. "c d". I attempted to use regex or write my own method to parse it, but had no luck.

Community
  • 1
  • 1
dv90
  • 13
  • 2
  • 5

1 Answers1

0

Definitely a duplicate as Bala R mentioned above.

Regex regex = new Regex(@"\w+|""[\w\s]*""");
var str = "ab \"c d\"";

var x = regex.Matches(str).Cast<Match>().ToList();