Regular and strings

 

1.

* Character sets, character sets?, Character Set +

eg: abc * d matches abcd abccd abccccd the like, * represents the foregoing character may not occur, can also occur one or more times (0, 1, multiple)

abc? d match abd abcd? In front of the most representative of the character appears only once or zero times (0, 1)

abc + d + match abcd abccd abcccd like characters represent at least once in front of the (1, multiple)

 

2.

[0-9]   0,1,2,3,4,5,6,7,8,9

 [Az] matches lowercase English words

strsubing //
// 0,123,456,789,012
var STR = 'adgfcbhjklada';
// start from the third to the seventh end is not included. 7
var str1 = str.substring (. 3,. 7);
// represents the second argument is omitted from the till the end of three
var Str3 str.substring = (. 3)
// low from the beginning until the three. 3-str.length
var str5 str.substring = (. 3, str.length -. 3)

Strsub //
// third from the start of seven elements behind
var str2 = str.substr (. 3,. 7)
// second argument is omitted from the beginning until the end of the third
var str4 = str.substr (3)
// start from the low three-up. 3 str.length
var STR6 str.substr = (. 3, str.length -. 3)
the console.log (str1, str2, Str3, str4, str5, STR6)


The indexOf indexOf // ( 'kW', [Formi])
// 012345678901234567890123456
var = Word "See you See you, One Day Day";
// return the keyword's standard
var index = word.indexOf ( "see" )
the console.log (index). 4 //
// returns next see a position index
index = word.indexOf ( "see", + index. 1)
the console.log (index). 8 //
// returns not found - 1
index = word.indexOf ( "hhh")
console.log (index) // - 1

// lastIndexOf
index = word.lastIndexOf("you")
console.log(index) //12
index = word.lastIndexOf("see", index - 'see'.length)
console.log(index) //24

 

// search to find the first matching canonical specification can not find a position returns -1
var kW = "See you by You See, One Day Day";
index = kw.search (/ you / IG)
the console.log (index)


// match regular keywords is acquired, content keywords returned null if none Returns
var ARR = "See you by You See, One Day Day";
index = arr.match (/ BO / IG);
the console.log (index ) // null

 


The RegExp //
// REG = var / NO / IG; // create direct
var of arr1 = 'by You See See you, One Day Day';
var arr2 is = [ "See", "you"];
// Create new new keywords
the RegExp new new REG = var (arr2.join ( "|"), 'IG');
the console.log (arr1.match (REG))
var REG1 = / you / IG;

Test // ()
var = reg1.test ARR3 (of arr1)
value console.log (arr3) // returns a boolean type

 

// exec()

var arr4 = "you see see you,one day day";
var reg2 = /([y|s|o|d])([o|e|a|n])([e|u|y])?/ig;
console.log(reg2.exec(arr4));
console.log(reg2.exec(arr4));
console.log(reg2.exec(arr4));
// console.log(reg2.exec(arr4));
var arr5 = reg2.exec(arr4)
console.log(arr5[0], arr5[2], arr5.index, reg2.lastIndex) //you o 12 15

mother

[AZ] matches uppercase letters

[0-9a-zA-Z] matches the above three cases

[\ U4e00- \ u9fa5] matches characters

 

3.

\ D matches that digital === >> [0-9]

\ W match that number, letter or _   

\ S Matches any whitespace characters, including spaces, tabs, page breaks, etc.

.  Matches any character

 

4. quantifier

{N} n is a nonnegative integer, indicates that the character n times abc {2} ===> abcc

{N,} n is a nonnegative integer, indicates that the character appears at least n times abc {3,} === >> abccc

{Nm} n, m are non-negative integer n <m times abc {2,4} = >>> abcc abccc abcccc n = m times at most appear to match at least the front characters appear

 

5. Special characters

^ Matches the beginning of the string === >>> [^ abc] matches the character except abc

$ Matches the input end of the string

\ Match the next character to be a special character or a literal character

| = >>> x | y matches the x or y

 

 

 

Common regular

qq number [1-9] \ d {4,11}

qq mail [1-9] \ d {4,11} @ [q] [q]. (com | cn)

NetEase mailbox [a-zA-Z1-9] @ [1] [6] [3] (com | cn).

ZIP [1-9] [0-9] {5}

ID number [1-9] \ d {5} ((18 | 19) \ d {2} | ([2] [0] [0-1] [0-9])) ((0 [1- 9]) | (10 | 11 | 12)) (([0-2] [1-9]) | 10 | 20 | 30 | 31) \ d {3} [0-9Xx]

Phone number? (\ +86 | 0086) \ s * 1 [3456789] \ d {9}

Password [AZ] [a-z0-9A-Z] {5,17} initials

Guess you like

Origin www.cnblogs.com/zhanghaifeng123/p/11830808.html