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