c# - Extracting parts of string with specific limits -
i have small problem. string has following format;
{"version":"5.14.1","id":"abcd","key":"266",...... etc i want abcd after "id" , have tried
i tried
string[] output; output = regex.matches(site,"(?<=(?:\"id\")\:\")([^\"]+)").cast<match>().select(m => m.value).toarray(); but when try compile says "unrecognized escape sequence" colon after id.
the regex expression used worked is:
(?<=(?:"id")\:")([^"]+) but i'm not sure how put inside regex.matches (i tried put \ before " says unrecognized escape sequence)
the regex error right -- : not special character within regular expression (except contextually in e.g. (?:) groups), can't escaped. (note there's 2 levels of escaping going on here: when \: seen within c# string, c# compiler decides : isn't special , silently leaves literal backslash preceding it; then, regex engine tries interpret , generates error.)
a regex want (for sample string, anyway) is:
"\"id\":\"([^\"]+)" but suggest using proper parser, since looks suspiciously json. regular expressions convenient, assumes lot input use 1 here (e.g. there data {'foo':'"id":"hmm"',"id": "realid"...
Comments
Post a Comment