/* Regular expression 1. Regular expressions are an independent discipline. 2. Regular expressions are a type of character model. specifically to do string format matching. 3. Regular expressions are generic. For example, the regular expression "^a{2}$" represents 2 a characters. Equivalent to "AA" \d digital \d Non-digital \w English letter \w non-English letter */public class Stringtest07{public static void Main (string[] args) {System.out.println ("AB". Matches ("^a{2}$")); String S1 = "ASDD33DFSDAF33DDSD55FDD3DSSF4343SDF455DDSDDDH565GGGH55DDHG";//replace DD with "medium" System.out.println ( S1.replaceall ("dd", "Medium"));//replace DD with "medium" System.out.println (S1.replaceall ("d{2}", "Medium");//Replace number with "medium" System.out.println (S1.replaceall ("\\d", "Medium"));//replace non-digits with "medium" System.out.println (S1.replaceall ("\\d", "Medium"));}}
This article is from the "Gaogaozi" blog, make sure to keep this source http://hangtiangazi.blog.51cto.com/8584103/1662505
Regular Expressions in Java