0

测试平台:http ://regexhero.net/tester/

输入字符串"_sql": "SELECT * FROM AA" 正则表达式(?:"_sql"[\s]*)([^,]*)

期望的结果:“SELECT * FROM AA”

现在我进入 c# 并将其编码:

    Match match = Regex.Match("_sql\": \"SELECT * FROM AA", @"(?:""_sql""[\s]*)([^,]*)");
    if (match.Success)
    {
        String value = match.Groups[0].Value;
        Console.WriteLine(value);
    }

为什么是match.Success假的?

4

2 回答 2

2

你忘了" "在你的字符串周围加上引号'。

尝试-

Match match = Regex.Match("\"_sql\": \"SELECT * FROM AA\"", @"(?:""_sql""[\s]*)([^,]*)");
于 2013-09-05T09:50:02.913 回答
0

您可以有一个单独的变量,并正确地对其进行转义。

string newVa = "\"_sql\": \"SELECT * FROM AA\"";
Match match = Regex.Match(newVa , @"(?:""_sql""[\s]*)([^,]*)");

或者

Match match = Regex.Match(@"""_sql"": ""SELECT * FROM AA""", @"(?:""_sql""[\s]*)([^,]*)");
于 2013-09-05T09:52:09.747 回答