[{name:v,category:1},{name:v,category:1},{name:v,category:4},{name:v,category:5}]
想要匹配出category为1name的值。
C#实现代码如下:
var text = "[{name:v,category:1},{name:v,category:1},{name:v,category:4},{name:v,category:5}]";
var regex = new Regex(@"{name:(.*?),category:1}");
var matches = regex.Matches(text);
foreach(Match match in matches)
{
Console.WriteLine(match.Groups[1]);
}
谢谢。
Java 代码的实现
String text = "[{name:a,category:1},{name:b,category:1},{name:c,category:4},{name:d,category:5}]"; Pattern pattern = Pattern.compile("name:(.*?),category:1"); Matcher matcher = pattern.matcher(text); while (matcher.find()) { System.out.println(matcher.group(1)); }
谢谢。