首页 新闻 会员 周边 捐助

正则表达式匹配

0
[已解决问题] 解决于 2017-04-18 11:56
[{name:v,category:1},{name:v,category:1},{name:v,category:4},{name:v,category:5}]

想要匹配出category为1name的值。

lucika.zh的主页 lucika.zh | 初学一级 | 园豆:54
提问于:2017-04-15 11:31
< >
分享
最佳答案
1

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]);
}
奖励园豆:5
dudu | 高人七级 |园豆:30925 | 2017-04-15 14:21

谢谢。

lucika.zh | 园豆:54 (初学一级) | 2017-04-18 11:55
其他回答(1)
0

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));
}
狼爷 | 园豆:1204 (小虾三级) | 2017-04-16 16:05

谢谢。

支持(0) 反对(0) lucika.zh | 园豆:54 (初学一级) | 2017-04-18 15:32
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册