1, about "\", in Java in the regular expression of the difference;
In other languages, "\ \" is expressed as: I want to insert a normal backslash in the regular expression;
In Java, "\ \" is represented as: I want to insert a regular expression back slash;
Eg: the regular expression for validating integers is \\d; If you want to insert a backslash: \\\\;
The newline and tab characters are \ n and \ t;
2. Special characters
| Greedy number of words |
| X ? |
X, not once or once |
| X * |
X, 0 or more times |
| X + |
X, one or more times |
| X {n} |
X, exactly n times |
| X {n,} |
X, at least n times |
| X {n,m} |
X, at least n times, but not more than m Times |
|
| Reluctant number of words |
| X ?? |
X, not once or once |
| X *? |
X, 0 or more times |
| X +? |
X, one or more times |
| X {n}? |
X, exactly n times |
| X {n,}? |
X, at least n times |
| X {n,m}? |
X, at least n times, but not more than m Times |
|
| Possessive number of words |
| X ?+ |
X, not once or once |
| X *+ |
X, 0 or more times |
| X ++ |
X, one or more times |
| X {n}+ |
X, exactly n times |
| X {n,}+ |
X, at least n times |
| X {n,m}+ |
X, at least n times, but not more than m Times |
Demo Code:
Packagecom.st.day20150525; Public classStringTest03 { Public StaticString message = "The class string includes methods for examining" + "individual characters of the sequence, fo R comparing strings, "+" for searching strings, for extracting substrings, and for "+" creating a Copy of a string with the characters translated to ' + ' uppercase or to lowercase. Case mapping was based on the Unicode "+" standard version specified by the Character class. "; Public Static voidMain (string[] args) {//1, using the built-in function in string, the character of the seriousSystem.out.println ("1243". Matches ("-?\\d+"))); System.out.println ("+911". Matches ("-?\\d+"))); System.out.println ("+911". Matches ("(-|\\+)? \\d+")); //2. Use String.Split () to separate strings from regular expression matchesstring[] Str01 = Message.split ("Of|to");//separate from where or to for(inti = 0; i < str01.length; i++) {System.out.println ("section" +i+ ":" +Str01[i]); } string[] Str02= Message.split ("\\w");//separate from the place where the spaces are for(inti = 0; i < str02.length; i++) {System.out.print ("+i+": "+str02[i]+" "); } }}
Regular expressions in Java--to be continued