java 正则获取 第一个匹配

String text="s = (90) e s = (60) e";
Pattern p=Pattern.compile("s.*\\((.*?)\\).*e");
Matcher m=p.matcher(text);
while(m.find())
{
System.out.println(m.group(1));
}
}

现在有两个相同的内容我想保持每次都获取第一个内容该怎么写。
内容:s = (90) e s = (60) e
内容第一个: s = (90) e
内容第二个: s = (60) e
("s.*\\((.*?)\\).*e") 这个能获取什么啊就是获取()里边的内容啊。

每次能获取90就是我要达到的效果。

第1个回答  推荐于2017-12-16
Matcher matcher = p.matcher(test);
while(matcher.find()){
result.add(matcher.group())};

matcher.find()会匹配第一个结果,后续会从这里继续往后匹配本回答被提问者采纳
第2个回答  2013-06-08
String text="s = (90) e s = (60) e";
text=text.replaceAll(" ", "");
Pattern p=Pattern.compile("\\((.*?)\\)");
Matcher m=p.matcher(text);
List<String> list = new ArrayList<String>();
while(m.find()){
   list.add(m.group(1));
    }
System.err.println(list.get(0));

第3个回答  2013-06-08
木有明白你啥意思

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网