当前位置: 代码迷 >> J2SE >> 请同志们帮俺看看小弟我的正则哪里出现了有关问题.
  详细解决方案

请同志们帮俺看看小弟我的正则哪里出现了有关问题.

热度:75   发布时间:2016-04-24 02:21:41.0
请同志们帮俺看看我的正则哪里出现了问题......
高人们好,再次请教正则...

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());}
------解决方案--------------------
探讨

[]符号没有转义
Java code
String str = "(([[indicator6]]+[[indicator8]])*2)/[[indicator9]]-10)/2+[[indicator1]]*2+([[indicator3]]-[[indicator4]]/[[indicator5]])-[[indicator10]]";
Pattern p = Pattern.compi……
  相关解决方案