我需要提取值11、12和1,即 =之后的值。
我试图做以下几件事
Matcher m = Pattern.compile("\\((.*?)\\)").matcher(s);
while (m.find()) {
list.add(m.group(1));
System.out.println(m.group(1));
}然后我将使用=进行拆分
有什么更好的方法吗?
发布于 2017-08-07 08:32:19
您可以使用这个regex =(\d+) (regex演示),它匹配=后面的一个或多个数字,如下所示:
String str = "(( Relationship=11 ) AND ( Relationship=12 ) AND ( Relationship=1 ))";
String regex = "=(\\d+)";
Pattern pattern = Pattern.compile(regex);
Matcher matcher = pattern.matcher(str);
while (matcher.find()) {
System.out.println(matcher.group(1));
}输出
11
12
1https://stackoverflow.com/questions/45542517
复制相似问题