Regular Expressions regex

Regular expressions exist in the matches method in String api

 

Common normal expression:

Character 
x character x 
\\ backslash character 
character class 
[ABC] a, b or C (Simple) 
[ ^ ABC] any character, in addition to a, b or C (negative) 
[A -zA- the Z] z to A or a to Z, including two letters (range 
predefined character classes 
. any characters (with a line terminator may or may not match the match) 
\ D figures: [ 0-9 ] 
\ D non-numeric: [ ^ 0- . 9 ] 
\ S whitespace: [\ T \ n-\ x0B \ F \ R & lt] 
\ S non-whitespace characters: [ ^ \ S] 
\ W word character: [A -za-Z ~ 0-9 ] 
\ W is a non-word character: [ ^ \ W] 
and Greedy quantifier 
X- ? X-, or once there is no 
X- * X-, zero or more times 
X- + X-, one or more 
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 

 

Case

Package day28_api.Integer_Int wrapper classes;
 / * 
 * check number qq 
* asked to be bits 5-15 
* 0 not begin with 
* are numbers have 

    the regular expression: is a set of rules can be used to match a string 

String. Boolean the matches (string REGEX) : determining whether the specified string matching the regular expression in the current, if the match returns true, otherwise to false 
* 
* 
    
 * / 
public  class QQ_Test {
     public  static  void main (string [] args) { 
        string QQ = " 012345 " ; 

        Boolean In Flag = qq.matches (" [1-9] [0-9] {4,14} " ); 
        System.out.println (In Flag); 
    } 
}

 

Export

 

Guess you like

Origin www.cnblogs.com/longesang/p/11262893.html