java中匹配/* explanation */的正则表达式怎么写?

解决方案 »

  1.   

     String str = "/* asfdasfdsaf */ /*asdfasdfsadfdsaf*dsa/asdfasf*/aaa";
        String regex = "/\\*/?(\\n|[^/]|[^*]/)*\\*/";
        Pattern p = Pattern.compile(regex);
        Matcher m = p.matcher(str);    if (m.find()) {
          String matchstr = m.group();
          System.out.println(matchstr);
        }
      

  2.   

    如果是这样的数据,你想得到什么?String str = "this is a comments /* test */ comments"; /* test2 */