Android進階-Regex

來源:互聯網
上載者:User

標籤:

  今天學習了Regex,感覺亞曆山大,有很多地方沒動,一溜號就講完了,課後自己又研究了一下,總算明白了點,防止忘記,分享下今天學的,

  

構建Regex

\d 等於 [0-9] 數字

\D 等於 [^0-9] 非數字

\s 等於 [ \t\n\x0B\f\r] 空白字元

\S 等於 [^ \t\n\x0B\f\r] 非空白字元

\w 等於 [a-zA-Z_0-9] 數字或是英文字

\W 等於 [^a-zA-Z_0-9] 非數字與英文字 

 

/d用法

 1 Pattern pattern = Pattern.compile("//d")

2 Matcher matcher = pattern.matcher("1")

3 System.out.print(matcher.matches); 

輸出匹配成功的字元

1         Pattern pattern = Pattern.compile("\\d+");2         Matcher matcher = pattern.matcher("234hui55651g23ghuihui6754hui");3         System.out.println("是否匹配成功"+matcher.matches());4         while (matcher.find()) {5             System.out.println("開始的位置"+matcher.start());6             System.out.println("匹配到的字元"+matcher.group());7             System.out.println("結束的位置"+matcher.end());8         }

 

分隔匹配成功的字元

        Pattern pattern = Pattern.compile("a");        String str = "12321a123123asd123123ad213123a";    //    System.out.println(pattern.split(str));        System.out.println(Arrays.toString(pattern.split(str)));

 

感覺自己寫的好亂,先不寫了,以後在寫把,勿噴

Android進階-Regex

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.