Skip to content

Instantly share code, notes, and snippets.

@leppie
Created March 20, 2013 17:06
Show Gist options
  • Save leppie/5206400 to your computer and use it in GitHub Desktop.
Save leppie/5206400 to your computer and use it in GitHub Desktop.
var re = new Regex(string.Format(@"
(({0} # switch
(?<name>[_A-Za-z][_\w]*) # name (any legal C# name)
({1} # sep + optional space
(((""(?<value>((\\"")|[^""])*)"")| # match a double quoted value (escape "" with \)
('(?<value>((\\')|[^'])*)'))| # match a single quoted value (escape ' with \)
(\{{(?<arrayval>[^\}}]*)\}})| # list value (escaped for string.Format)
(?<value>\S+)) # any single value
)?)| # sep option + list
(((""(?<value>((\\"")|[^""])*)"")| # match a double quoted value (escape "" with \)
('(?<value>((\\')|[^'])*)'))| # match a single quoted value (escape ' with \)
(\{{(?<arrayval>[^\}}]*)\}})| # list value (escaped for string.Format)
(?<value>\S+)))* # any single value",
Regex.Escape(prefix),
seperator.Trim() == string.Empty ? @"\s+" : @"\s*" + Regex.Escape(seperator) + @"\s*"
),
RegexOptions.Compiled | RegexOptions.ExplicitCapture | RegexOptions.IgnorePatternWhitespace);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment