您可以使用
Regex rg2 = new Regex(@"^\[""[a-zA-Z0-9]+""(?:,\s*""[a-zA-Z0-9]+"")*]$");
Regex rg2 = new Regex(@"\A\[""[a-zA-Z0-9]+""(?:,\s*""[a-zA-Z0-9]+"")*]\z");
请参阅
C# demo
:
string text = "[\"a1\",\"a2\"]";
Regex rg2 = new Regex(@"\A\[""[a-zA-Z0-9]+""(?:,\s*""[a-zA-Z0-9]+"")*]\z");
Console.WriteLine(rg2.IsMatch(text)); // => True
详细信息
:
-
\A
-字符串的开头
-
\["
-a
["
固定字符串
-
[a-zA-Z0-9]+
-一个或多个ASCII字母/数字
-
"
-双引号
-
(?:,\s*"[a-zA-Z0-9]+")*
-零次或多次重复
-
,
-逗号
-
\s*
-零个或多个空白
-
"[a-zA-Z0-9]+"
-
“
,一个或多个ASCII字母数字字符,
“
-
]
-a
]
烧焦
-
\z
-绳子的末端。