Some methods of regular expressions

match method, the object is to string

Action: obtaining an array of matching, if the global matching opening, and a plurality of arrays to match the string, a plurality of returns, by array subscript of view, each of which is the same character string stored

search method

Returns the first matching position, first matching string to the position of the letters, can not find returns -1, (one that does not open globally, are the same)

replace method

Inside with two parameters, the first one is to be replaced, is to be replaced with a second (global turn on for as long as the match)

split method

For example, the sentence "this is a dog! This is a dog" if to split the incoming '! 'No, it will replace the two arrays to'! 'Separate number, and does not include it.

RegExp static properties: no need to create an object, you can directly use the pain had called directly RegExp._

Another example is the opposite properties

Third, access to (in the role of a regular expression to write some special characters) control

Character matches:

. (Point): the method can be any character (newline does not match) will not write more write less

If not then i case there is a difference

As long as there is a match can be matched to the pattern of all the leading and independent of

This can also be written with repeated characters in combination with

 

 

Repeat match:

x is the leading character in it

(.) And the other point is the same combination

 Anchor characters:

This time 44444oogle does not hold, because it is starting from scratch match

 

Special characters match:

If there is no symbol $ {4,8} behind, then e is any number greater than three pairs, because match

 

Guess you like

Origin www.cnblogs.com/kongbursi-2292702937/p/10690397.html
Recommended