regex – c # The fastest way to get the values ​​of a string

If you do not want to use a JSON library, you can combine the two regex expressions into one and use named groups. (?expression).

Private static regex _regex =
new Regex (@ "" "(?. *) "". *? (? d * .  d *) ", RegexOptions.Compiled);

The you get the result with

var match = _regex.Match ("{key = " foo  ", value = 1,6557,}");
string key = match.Groups["key"].Value;
string value = match.Groups["value"].Value;

Note that in a word-for-word string, double quotation marks must be avoided by doubling them. The named group key does not include quotation marks, so you get the key directly.

So, I basically have the regex

key_expression. *? value_expression

Both expressions are separated by . *?. The quotation mark indicates * to be lazy, that is, to take as few characters as possible. Otherwise, the digits before the decimal point will be swallowed.