java中的Regex

來源:互聯網
上載者:User

標籤:Regex

/*Regex1.Regex是一門獨立的學科。2.Regex是一種字元模型。專門做字串格式匹配的。3.Regex是通用的。例如:Regex "^a{2}$" 表示 2個a字元.等同於 "aa"\d 數字\D 非數字\w 英文字母\W 非英文字母*/public class StringTest07{public static void main(String[] args){System.out.println("ab".matches("^a{2}$"));String s1 = "asdd33dfsdaf33ddsd55fdd3dssf4343sdf455ddsdddh565gggh55ddhg";//將dd替換為"中"System.out.println(s1.replaceAll("dd", "中"));//將dd替換為"中"System.out.println(s1.replaceAll("d{2}", "中"));//將數字替換為"中"System.out.println(s1.replaceAll("\\d", "中"));//將非數字替換為"中"System.out.println(s1.replaceAll("\\D", "中"));}}


本文出自 “gaogaozi” 部落格,請務必保留此出處http://hangtiangazi.blog.51cto.com/8584103/1662505

java中的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.