Two regular expression syntax - quantifier

quantifier

quantifier description
n+ Matches any string of at least one n.
n* Matches any string contains zero or more occurrences of n.
n? Matches any zero or a string containing n.
n{X} Matching string comprising the sequence of X n.
n {X, Y} It contains the string matching sequences X or Y is a n.
n{X,} X matching string comprising at least a sequence of n.
n$ Matches any string of n ends.
^n Matches any string that begins with n.
?=n Immediately followed by the specified string matches any character string n.
?!n Immediately thereafter not match any character string specified string n.

 

/ *
* Create a regular expression used to check whether a string contains ab &
*
* quantifier
* - number of times a content can be provided by the quantifier occurrence
* - valid only for a quantifier content in front of him
* - {} occurring just a few mean
* - {m, n} m to n times appear content
* - (ab &) and the content can be set as a
* - {3} occurs three or more times the contents
* /

 

 N is the n +: + is at least equivalent to a mean {1}

 

 Is the n * n: Number * means zero or more, corresponds to {0}

 

 Regular n? They are:? 0 or one equivalent, equivalent to {0,1}

 

 ^ A with a check string does not start with a

 

 

Check with a & ends in a string is not

 

 

If the regular use both ^ & string that represents full compliance with regular expressions

 

 

 

 

 

 Practice writing a detected phone number regular expression!

/ *
* Create a regular expression to check if a string is a valid phone number
* regular phone number:
* 18136511586
* 1. outset
* 2. The second digit is any number 3-9
* 3. after three is an arbitrary number 9
* /

 

 

Guess you like

Origin www.cnblogs.com/niuyaomin/p/11609594.html