2 回答

TA貢獻(xiàn)1851條經(jīng)驗(yàn) 獲得超4個(gè)贊
您可以使用
Regex.Matches(filters.queryString, @"\[family]:\s*""([^""]*)""")
.Cast<Match>()
.Select(m => m.Groups[1].Value.Trim())
.ToList();
您需要的值在第 1 組中,并且使用.Trim()
,將從這些子字符串中刪除前導(dǎo)/尾隨空格。
圖案詳情
\[family]:
- 一個(gè)[family]
子串\s*
- 0+ 個(gè)空白字符"
- 雙引號(hào)([^"]*)
- 捕獲組 #1:零個(gè)或多個(gè)字符,而不是"
"
- 雙引號(hào)。
var test = "and ( [family]: \" trees \" or [family]: \" colors \" )";
var result = Regex.Matches(test, @"\[family]:\s*""([^""]*)""")
.Cast<Match>()
.Select(m => m.Groups[1].Value.Trim())
.ToList();
foreach (var s in result)
Console.WriteLine(s); // => trees, colors
- 2 回答
- 0 關(guān)注
- 328 瀏覽
添加回答
舉報(bào)