欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

java中正則表達(dá)式實(shí)例詳解

 更新時(shí)間:2017年04月14日 14:41:41   投稿:lqh  
這篇文章主要介紹了java中正則表達(dá)式實(shí)例詳解的相關(guān)資料,需要的朋友可以參考下

Java中正則表達(dá)式運(yùn)用實(shí)例(參看java中正則表達(dá)式運(yùn)用詳解):

測試代碼

package test; 
/** 
 * 在String的matches()方法,split()方法中使用正則表達(dá)式. 
 * @author fhd001 
 */ 
public class RegexTest { 
 
  public static void main(String[] args) { 
 
    /* 
     * 普通字符 
     */ 
    String str1 = "abc45abc345"; 
    String[]arr1 = str1.split("abc"); 
    for (String string : arr1) { 
      System.out.print(string+"-->"); 
    } 
    System.out.println(); 
     
     
    /* 
     * 簡單的轉(zhuǎn)義字符 
     * 在java中轉(zhuǎn)義字符時(shí)一定要用雙反斜線,兩個(gè)斜線轉(zhuǎn)義成一個(gè)斜線, 
     * 在用這個(gè)斜線字符轉(zhuǎn)義那些特殊字符. 
     */ 
    String str2 = "^$()[]{}.?+*|"; 
    boolean flag = str2.matches("http://^//$//(//)//[//]//{//}//.//?//+//*//|"); 
    System.out.println(flag); 
     
     
    /* 
     * 轉(zhuǎn)義字符 /Q.../E. 
     */ 
    String str3 = "^$()[]{}.?+*|99999"; 
    boolean flag2 = str3.matches("http://Q^$()[]{}.?+*|//E//d{5}"); 
    System.out.println(flag2); 
     
     
    /* 
     * 字符集合 
     */ 
    String str4 = "dfddri334"; 
    boolean flag4 = str4.matches(".+"); 
    System.out.println(flag4); 
     
    String str5 = "#$%^*())%"; 
    boolean flag5 = str5.matches("http://W{9}"); 
    System.out.println(flag5); 
     
    String str6 = "4gffmdkekrhhr"; 
    boolean flag6 = str6.matches("http://w+"); 
    System.out.println(flag6); 
     
    String str7 = "fjfdke  eett "; 
    boolean flag7 = str7.matches("http://w+//s+//w{4}//s?"); 
    System.out.println(flag7); 
     
    String str8 = "  erefff  "; 
    boolean flag8 = str8.matches("http://s+//S+//s+"); 
    System.out.println(flag8); 
     
    String str9 = "456776888"; 
    boolean flag9 = str9.matches("http://d+"); 
    System.out.println(flag9); 
     
     
    String str10 = "rtydfgrgwvr "; 
    boolean flag10 = str10.matches("http://D+"); 
    System.out.println(flag10); 
     
     
    /* 
     * 自定義字符集合 [ ] 
     */ 
    String str11 = "fdfeetg 34566"; 
    boolean flag11 = str11.matches("[fdetg]+//s+[3-6]+"); 
    System.out.println(flag11); 
     
     
    String str12 = "rtyuie  5768"; 
    boolean flag12 = str12.matches("[^abcdf]+//s+[^1234]+"); 
    System.out.println(flag12); 
     
     
    /* 
     * 匹配次數(shù)限定符 
     */ 
     
    //貪婪模式 
    String str13 = "ytreggcv454444444333"; 
    boolean flag13 = str13.matches("http://w{20}"); 
    System.out.println(flag13); 
     
    boolean flag14 = str13.matches("http://w{10,21}"); 
    System.out.println(flag14); 
     
    boolean flag15 = str13.matches("http://w{18,}"); 
    System.out.println(flag15); 
     
    String str14 = "4"; 
    boolean flag16 = str14.matches("http://d?"); 
    System.out.println(flag16); 
     
    String str15 = "ddcvgt"; 
    boolean flag17 = str15.matches("http://D+//d?"); 
    System.out.println(flag17); 
     
    String str16 = "e33tf44t44t"; 
    boolean flag18 = str16.matches("http://w+//W*"); 
    System.out.println(flag18); 
     
    //勉強(qiáng)模式(只舉一例) 
    String str17 = "34567ghjkkld"; 
    boolean flag19 = str17.matches("http://d{2,7}?//w{8,11}"); 
    System.out.println(flag19); 
     
    //占有模式(只舉一例) 
    String str18 = "22222ddddd"; 
    boolean flag20 = str18.matches("http://d{2,5}+//w{6}"); 
    System.out.println(flag20); 
     
    /* 
     * 字符邊界 
     */ 
    String str19 = "a444545rot44tm"; 
    boolean flag21 = str19.matches("^a//w+m$"); 
    System.out.println(flag21); 
     
     
    /* 
     * 選擇表達(dá)式 xxx | xxx 
     */ 
    String str20 = "abc123abc"; 
    boolean flag22 = str20.matches("(abc|123){3}"); 
    System.out.println(flag22); 
     
     
    /* 
     * 分組 ( ). 
     * 以上修飾符都是針對一個(gè)字符進(jìn)行修飾.如果要對一組字符進(jìn)行 
     * 修飾就要用到() 
     */ 
    String str21 = "123qwe123qwe"; 
    boolean flag23 = str21.matches("(123qwe){2}"); 
    System.out.println(flag23); 
     
     
    /* 
     * []中的交集與并集 
     */ 
    String str22 = "abcdefgh1234567"; 
    boolean flag24 = str22.matches("[a-z1-9]+");    //并集 
    System.out.println(flag24); 
     
    boolean flag25 = str22.matches("[a-z1-9&&[a-h1-7]]+"); //交集 
    System.out.println(flag25); 
  } 
} 
 

結(jié)果代碼

-->45-->345--> 
true 
true 
true 
true 
true 
true 
true 
true 
true 
true 
true 
true 
true 
true 
true 
true 
true 
true 
false 
true 
true 
true 
true 
true 

感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!

相關(guān)文章

  • java使用GeoTools讀取shp文件并畫圖的操作代碼

    java使用GeoTools讀取shp文件并畫圖的操作代碼

    GeoTools是ArcGis地圖與java對象的橋梁,今天通過本文給大家分享java使用GeoTools讀取shp文件并畫圖,文章通過實(shí)例代碼給大家介紹的非常詳細(xì),需要的朋友參考下吧
    2021-07-07
  • java8使用Stream API方法總結(jié)

    java8使用Stream API方法總結(jié)

    在本篇文章里小編給大家分享了關(guān)于java8使用Stream API方法相關(guān)知識點(diǎn),需要的朋友們學(xué)習(xí)下。
    2019-04-04
  • java中@EnableAutoConfiguration注解使用

    java中@EnableAutoConfiguration注解使用

    在Spring Boot框架中,@EnableAutoConfiguration是一種非常重要的注解,本文就來介紹一下java中@EnableAutoConfiguration注解使用,感興趣的可以了解一下
    2023-11-11
  • Java編寫簡易rabbitmq生產(chǎn)者與消費(fèi)者的代碼

    Java編寫簡易rabbitmq生產(chǎn)者與消費(fèi)者的代碼

    開發(fā)時(shí)經(jīng)常與其它系統(tǒng)用rabbitmq對接,當(dāng)需要自測時(shí),還是自己寫rabbitmq生產(chǎn)者、消費(fèi)者自測方便些,下面給大家總結(jié)使用java編寫簡易rabbitmq的方法,感興趣的朋友一起看看吧
    2023-11-11
  • MyBatis中調(diào)用存儲過程和函數(shù)的實(shí)現(xiàn)示例

    MyBatis中調(diào)用存儲過程和函數(shù)的實(shí)現(xiàn)示例

    在MyBatis中調(diào)用存儲過程和函數(shù)是一個(gè)相對高級的特性,本文主要介紹了MyBatis中調(diào)用存儲過程和函數(shù)的實(shí)現(xiàn)示例,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2024-07-07
  • Java RandomAccessFile基本文件操作示例

    Java RandomAccessFile基本文件操作示例

    這篇文章主要介紹了Java RandomAccessFile基本文件操作,結(jié)合實(shí)例形式分析了Java基于RandomAccessFile實(shí)現(xiàn)文件讀寫及文件隨機(jī)訪問相關(guān)操作技巧,需要的朋友可以參考下
    2019-09-09
  • Idea打War包流程圖文教程

    Idea打War包流程圖文教程

    這篇文章主要給大家介紹了關(guān)于Idea打War包流程的相關(guān)資料,IDEA導(dǎo)出war包的方式與MyEclipse有一點(diǎn)不同,文中通過圖文介紹的非常詳細(xì),需要的朋友可以參考下
    2023-08-08
  • 使用Postman傳遞arraylist數(shù)據(jù)給springboot方式

    使用Postman傳遞arraylist數(shù)據(jù)給springboot方式

    這篇文章主要介紹了使用Postman傳遞arraylist數(shù)據(jù)給springboot方式,具有很好的參考價(jià)值,希望對大家有所幫助。如有錯(cuò)誤或未考慮完全的地方,望不吝賜教
    2021-12-12
  • JDK動態(tài)代理與CGLib動態(tài)代理的區(qū)別對比

    JDK動態(tài)代理與CGLib動態(tài)代理的區(qū)別對比

    今天小編就為大家分享一篇關(guān)于JDK動態(tài)代理與CGLib動態(tài)代理的區(qū)別對比,小編覺得內(nèi)容挺不錯(cuò)的,現(xiàn)在分享給大家,具有很好的參考價(jià)值,需要的朋友一起跟隨小編來看看吧
    2019-02-02
  • Java簡單獲取字符串像素的方法

    Java簡單獲取字符串像素的方法

    這篇文章主要介紹了Java簡單獲取字符串像素的方法,涉及Java針對字符串字體操作的相關(guān)技巧,具有一定參考借鑒價(jià)值,需要的朋友可以參考下
    2015-10-10

最新評論