当前位置:   article > 正文

java正则表达式匹配c语言注释

java正则表达式匹配c语言注释

https://blog.csdn.net/weixin_43732798/article/details/100067094

import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
/*
ddd
eee
 */
public class Main3 {
    public static void main(String[] args) throws IOException {
        String filePath = "./src/Main3.java";  //hehe
        String jsContent = new String(Files.readAllBytes(Paths.get(filePath)));
//        System.out.println(jsContent);
        Pattern p=Pattern.compile("/\\*.*?\\*/",Pattern.MULTILINE|Pattern.DOTALL);
        Matcher m=p.matcher(jsContent);
        while(m.find()){
            System.out.println(m.group()+"   位置:["+m.start()+","+m.end()+"]");
        }
    }
}

  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/花生_TL007/article/detail/413899
推荐阅读
相关标签
  

闽ICP备14008679号