以下是我测试的代码与我的模式不匹配:
using System;
using System.Text.RegularExpressions;
public class Program
{
public static void Main()
{
string test = "Error during request to host: 123.456.78, port: 1234 with status 500 and message={\n \"messageID\": \"TEST_ID\",\n \"messageArgs\": [\n \"12345\"\n ],\n \"message\": \"The test having ID \\\"12345\\\" was not found.\",\n \"recommendedActions\": []\n}";
Match m = Regex.Match(test, @"message=({.*})", RegexOptions.IgnoreCase | RegexOptions.Multiline);
Console.WriteLine(m.Success);
Console.WriteLine(test);
if(m.Success){
Console.WriteLine(m.Groups[0]);
Console.WriteLine(m.Groups[1]);
}
}
}
由于某种原因,这不起作用,但我相信这种模式对于捕获message = {}内部的内容是正确的。
这是在正则表达式101中工作:https://regex101.com/r/yY2bQ4/1