高人们好,再次请教正则...
public class RegularExpress
{
public static void main(String[] args) {
String str = "(([[indicator6]]+[[indicator8]])*2)/[[indicator9]]-10)/2+[[indicator1]]*2+([[indicator3]]-[[indicator4]]/[[indicator5]])-[[indicator10]]";
Pattern p = Pattern.compile("[[indicator\\d*]]");
Matcher m = p.matcher(str);
while(m.find()) {
System.out.println(m.group());
}
}
}
我的本意是想取出[[indicator6]]、[[indicator8]]、[[indicator9]]、[[indicator1]]、[[indicator3]]、[[indicator4]]、[[indicator5]]、[[indicator10]]
但是上面的正则不对头,请同志们指点....
------解决方案--------------------
[]符号没有转义
- Java code
String str = "(([[indicator6]]+[[indicator8]])*2)/[[indicator9]]-10)/2+[[indicator1]]*2+([[indicator3]]-[[indicator4]]/[[indicator5]])-[[indicator10]]";Pattern p = Pattern.compile("\\[\\[indicator\\d*\\]\\]"); //注意转义Matcher m = p.matcher(str);while(m.find()) { System.out.println(m.group());}
------解决方案--------------------