java正则 以什么开始,以什么结束


public class RegTest {

    public static void main(String[] args){
        String regex = "\\[([\\s\\S]*?)\\[";
        String str = "[begin]111[end] [begin]222[end] [begin]333[end] ";
        getQuestionResolution(regex, str);

        System.out.println("------------------------");

        String regex2 = "\\[([\\s\\S]*)\\[";
        getQuestionResolution(regex2, str);

    }
    private static void getQuestionResolution(String regex,String html){

        Matcher matcher = Pattern.compile(regex).matcher(html);
        while (matcher.find()){
            //group是针对()来说的,group(0)就是指的整个串,group(1) 指的是第一个括号里的东西,group(2)指的第二个括号里的东西。
       //
group()= group(0)

System.out.println(matcher.group().trim());
 } } }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM