最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

java的正則表達式你知道多少

 更新時間:2022年02月07日 11:50:39   作者:xiaostudy  
這篇文章主要為大家詳細介紹了java的正則表達式,使用表格進行介紹,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來幫助
字符
x字符 x
\\反斜線字符
\0n帶有八進制值 0 的字符 n (0 <= n <= 7)
\0nn帶有八進制值 0 的字符 nn (0 <= n <= 7)
\0mnn帶有八進制值 0 的字符 mnn(0 <= m <= 3、0 <= n <= 7)
\xhh帶有十六進制值 0x 的字符 hh
\uhhhh帶有十六進制值 0x 的字符 hhhh
\t制表符 ('\u0009')
\n新行(換行)符 ('\u000A')
\r回車符 ('\u000D')
\f換頁符 ('\u000C')
\a報警 (bell) 符 ('\u0007')
\e轉義符 ('\u001B')
\cx對應于 x 的控制符
字符類
[abc]a、b 或 c(簡單類)
[^abc]任何字符,除了 a、b 或 c(否定)
[a-zA-Z]a 到 z 或 A 到 Z,兩頭的字母包括在內(范圍)
[a-d[m-p]]a 到 d 或 m 到 p[a-dm-p](并集)
[a-z&&[def]]d、e 或 f(交集)
[a-z&&[^bc]]a 到 z,除了 b 和 c[ad-z](減去)
[a-z&&[^m-p]]a 到 z,而非 m 到 p[a-lq-z](減去)
預定義字符類
.任何字符(與行結束符可能匹配也可能不匹配)
\d數字:[0-9]
\D非數字: [^0-9]
\s空白字符:[ \t\n\x0B\f\r]
\S非空白字符:[^\s]
\w單詞字符:[a-zA-Z_0-9]
\W非單詞字符:[^\w]
Greedy 數量詞
X?X,一次或一次也沒有
X*X,零次或多次
X+X,一次或多次
X{n}X,恰好 n 次
X{n,}X,至少 n 次
X{n,m}X,至少 n 次,但是不超過 m 次
Reluctant 數量詞
X??X,一次或一次也沒有
X*?X,零次或多次
X+?X,一次或多次
X{n}?X,恰好 n 次
X{n,}?X,至少 n 次
X{n,m}?X,至少 n 次,但是不超過 m 次

例子 

package com.xiaostudy;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class MyPattern {
    public static void main(String[] args) {
    }
    private static void demo_Reluctant() {
        // 檢驗規(guī)則,單個字母,“+”表示:0次或多次,后面多加一個“?”與不加的區(qū)別是:不加的話表示只匹配一次,加的話表示匹配多次
        String regex = ".+?222";
        // 要檢驗的對象
        String str = "xx222xx222xx222xx222";
        // 編譯正則表達式
        Pattern pattern = Pattern.compile(regex);
        // 創(chuàng)建匹配器,給定輸入與此模式的匹配
        Matcher matcher = pattern.matcher(str);
        while (matcher.find())
            System.out.println(matcher.start() + "=====" + matcher.end());
        // 匹配,返回結果
        boolean b = matcher.matches();
        if (b)
            System.out.println(true);
        else
            System.out.println(false);
    }
    private static void demo_aBAb() {
        // 檢驗規(guī)則,字母集,“+”表示:0個或多個
        String regex = "[abcd]+";
        // 要檢驗的對象
        String str = "adbcdbaDACDBDAC";
        // 編譯正則表達式,不區(qū)分大小寫
        Pattern pattern = Pattern.compile(regex, Pattern.CASE_INSENSITIVE);
        // 創(chuàng)建匹配器,給定輸入與此模式的匹配
        Matcher matcher = pattern.matcher(str);
        // 匹配,返回結果
        boolean b = matcher.matches();
        if (b)
            System.out.println(true);
        else
            System.out.println(false);
    }
    private static void demo_abcd() {
        // 檢驗規(guī)則,字母集,“+”表示:0個或多個
        String regex = "[abcd]+";
        // 要檢驗的對象
        String str = "adbcdabdcddbadbc";
        // 編譯正則表達式
        Pattern pattern = Pattern.compile(regex);
        // 創(chuàng)建匹配器,給定輸入與此模式的匹配
        Matcher matcher = pattern.matcher(str);
        // 匹配,返回結果
        boolean b = matcher.matches();
        if (b)
            System.out.println(true);
        else
            System.out.println(false);
    }
    private static void demo_123no() {
        // 檢驗規(guī)則,非數字集,“+”表示:0個或多個
        String regex = "[^1-9]+";// 等價于\\D+
        // 要檢驗的對象
        String str = "+sdoi#$@%@#";
        // 編譯正則表達式
        Pattern pattern = Pattern.compile(regex);
        // 創(chuàng)建匹配器,給定輸入與此模式的匹配
        Matcher matcher = pattern.matcher(str);
        // 匹配,返回結果
        boolean b = matcher.matches();
        if (b)
            System.out.println(true);
        else
            System.out.println(false);
    }
    private static void demo_123() {
        // 檢驗規(guī)則,數字集,“+”表示:0個或多個
        String regex = "[1-9]+";// 等價于\\d+
        // 要檢驗的對象
        String str = "123";
        // 編譯正則表達式
        Pattern pattern = Pattern.compile(regex);
        // 創(chuàng)建匹配器,給定輸入與此模式的匹配
        Matcher matcher = pattern.matcher(str);
        // 匹配,返回結果
        boolean b = matcher.matches();
        if (b)
            System.out.println(true);
        else
            System.out.println(false);
    }
    private static void demo_2() {
        // 檢驗規(guī)則,單個數字
        String regex = "[1-9]";
        // 要檢驗的對象
        String str = "2";
        // 編譯正則表達式
        Pattern pattern = Pattern.compile(regex);
        // 創(chuàng)建匹配器,給定輸入與此模式的匹配
        Matcher matcher = pattern.matcher(str);
        // 匹配,返回結果
        boolean b = matcher.matches();
        if (b)
            System.out.println(true);
        else
            System.out.println(false);
    }
    private static void demo_nm() {
        // 檢驗規(guī)則,單個字母,“{n,m}”表示:出現n次到m次之間,包括他們本身
        String regex = "x{3,5}";
        // 要檢驗的對象
        String str = "xxxxx";
        // 編譯正則表達式
        Pattern pattern = Pattern.compile(regex);
        // 創(chuàng)建匹配器,給定輸入與此模式的匹配
        Matcher matcher = pattern.matcher(str);
        // 匹配,返回結果
        boolean b = matcher.matches();
        if (b)
            System.out.println(true);
        else
            System.out.println(false);
    }
    private static void demo_n0() {
        // 檢驗規(guī)則,單個字母,“{n,}”表示:出現n次或以上
        String regex = "x{3,}";
        // 要檢驗的對象
        String str = "xxxx";
        // 編譯正則表達式
        Pattern pattern = Pattern.compile(regex);
        // 創(chuàng)建匹配器,給定輸入與此模式的匹配
        Matcher matcher = pattern.matcher(str);
        // 匹配,返回結果
        boolean b = matcher.matches();
        if (b)
            System.out.println(true);
        else
            System.out.println(false);
    }
    private static void demo_n() {
        // 檢驗規(guī)則,單個字母,“{n}”表示:就出現n次
        String regex = "x{3}";
        // 要檢驗的對象
        String str = "xxx";
        // 編譯正則表達式
        Pattern pattern = Pattern.compile(regex);
        // 創(chuàng)建匹配器,給定輸入與此模式的匹配
        Matcher matcher = pattern.matcher(str);
        // 匹配,返回結果
        boolean b = matcher.matches();
        if (b)
            System.out.println(true);
        else
            System.out.println(false);
    }
    private static void demo_xxx0() {
        // 檢驗規(guī)則,單個字母,“+”表示:0次或多次
        String regex = "x+";
        // 要檢驗的對象
        String str = "xxx";
        // 編譯正則表達式
        Pattern pattern = Pattern.compile(regex);
        // 創(chuàng)建匹配器,給定輸入與此模式的匹配
        Matcher matcher = pattern.matcher(str);
        // 匹配,返回結果
        boolean b = matcher.matches();
        if (b)
            System.out.println(true);
        else
            System.out.println(false);
    }
    private static void demo_xxx() {
        // 檢驗規(guī)則,單個字母,“*”表示:一次或多次
        String regex = "x*";
        // 要檢驗的對象
        String str = "xxx";
        // 編譯正則表達式
        Pattern pattern = Pattern.compile(regex);
        // 創(chuàng)建匹配器,給定輸入與此模式的匹配
        Matcher matcher = pattern.matcher(str);
        // 匹配,返回結果
        boolean b = matcher.matches();
        if (b)
            System.out.println(true);
        else
            System.out.println(false);
    }
    private static void demo_x_01() {
        // 檢驗規(guī)則,單個字母,“?”表示:一次或一次都沒有
        String regex = "x?";
        // 要檢驗的對象
        String str = "x";
        // 編譯正則表達式
        Pattern pattern = Pattern.compile(regex);
        // 創(chuàng)建匹配器,給定輸入與此模式的匹配
        Matcher matcher = pattern.matcher(str);
        // 匹配,返回結果
        boolean b = matcher.matches();
        if (b)
            System.out.println(true);
        else
            System.out.println(false);
    }
    private static void demo_00() {
        // 檢驗規(guī)則,單個字母,“.”表示:任何字符
        String regex = ".";
        // 要檢驗的對象
        String str = "x";
        // 編譯正則表達式
        Pattern pattern = Pattern.compile(regex);
        // 創(chuàng)建匹配器,給定輸入與此模式的匹配
        Matcher matcher = pattern.matcher(str);
        // 匹配,返回結果
        boolean b = matcher.matches();
        if (b)
            System.out.println(true);
        else
            System.out.println(false);
    }
    private static void demo_x() {
        // 檢驗規(guī)則,單個字母
        String regex = "x";// 等價于\\w、[a-z]
        // 要檢驗的對象
        String str = "x";
        // 編譯正則表達式
        Pattern pattern = Pattern.compile(regex);
        // 創(chuàng)建匹配器,給定輸入與此模式的匹配
        Matcher matcher = pattern.matcher(str);
        // 匹配,返回結果
        boolean b = matcher.matches();
        if (b)
            System.out.println(true);
        else
            System.out.println(false);
    }
}

總結

本篇文章就到這里了,希望能夠給你帶來幫助,也希望您能夠多多關注腳本之家的更多內容!

相關文章

  • 在Java中Collection的一些常用方法總結

    在Java中Collection的一些常用方法總結

    今天給大家?guī)淼闹R是關于Java的,文章圍繞著Java中Collection的一些常用方法展開,文中有非常詳細的介紹及代碼示例,需要的朋友可以參考下
    2021-06-06
  • springmvc接收json串,轉換為實體類List方法

    springmvc接收json串,轉換為實體類List方法

    今天小編就為大家分享一篇springmvc接收json串,轉換為實體類List方法,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-08-08
  • Java裝飾者模式的深入了解

    Java裝飾者模式的深入了解

    這篇文章主要為大家介紹了Java裝飾者模式,具有一定的參考價值,感興趣的小伙伴們可以參考一下,希望能夠給你帶來幫助
    2022-01-01
  • 使用javaMail實現發(fā)送郵件

    使用javaMail實現發(fā)送郵件

    這篇文章主要為大家詳細介紹了使用javaMail實現發(fā)送郵件,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下
    2022-08-08
  • Java中使用Preconditions來檢查傳入參數介紹

    Java中使用Preconditions來檢查傳入參數介紹

    這篇文章主要介紹了Java中使用Preconditions來檢查傳入參數介紹,本文只是作為一個簡單的用法介紹,需要的朋友可以參考下
    2015-06-06
  • jedis的borrow行為方法源碼解讀

    jedis的borrow行為方法源碼解讀

    這篇文章主要為大家介紹了jedis的borrow行為方法源碼解讀,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-09-09
  • JAVA設置手動提交事務,回滾事務,提交事務的操作

    JAVA設置手動提交事務,回滾事務,提交事務的操作

    這篇文章主要介紹了JAVA設置手動提交事務,回滾事務,提交事務的操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-04-04
  • SpringBoot獲取Request對象的幾種方法

    SpringBoot獲取Request對象的幾種方法

    HttpServletRequest 簡稱 Request,它是一個 Servlet API 提供的對象,用于獲取客戶端發(fā)起的 HTTP 請求信息,那么問題來了,在 Spring Boot 中,獲取 Request 對象的方法有哪些?所以本文給大家介紹了SpringBoot獲取Request對象的幾種方法,需要的朋友可以參考下
    2024-11-11
  • Java String 字符串常量池解析

    Java String 字符串常量池解析

    這篇文章主要介紹了Java String 字符串常量池解析,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2019-08-08
  • Java多線程Future松獲取異步任務結果輕松實現

    Java多線程Future松獲取異步任務結果輕松實現

    這篇文章主要為大家介紹了Java多線程Future松獲取異步任務結果輕松實現方法,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進步,早日升職加薪
    2023-04-04

最新評論

涞源县| 鄂托克旗| 和田县| 女性| 开远市| 秦安县| 桃源县| 阿克陶县| 徐闻县| 沧源| 蓬溪县| 翁源县| 浮梁县| 宣汉县| 格尔木市| 昭觉县| 三都| 谷城县| 大足县| 斗六市| 娱乐| 荃湾区| 岳池县| 岳阳县| 如东县| 靖州| 安龙县| 英山县| 井研县| 鹤岗市| 长乐市| 巴林右旗| 萨迦县| 那坡县| 故城县| 百色市| 金寨县| 商丘市| 轮台县| 蒲江县| 河间市|