JavaScript regular expressions for the Web front-end
There is code behind:
\d represents a digital \d??0or a \d+ + represents one or more \d{3} represents three \d{3,5} represents three to five \d{3,} indicates that at least one occurrence3Times \d* * indicates0To any \b that represents a word boundary \b represents a non-word boundary \bis\b means find " is". Represents any character \ Representation translationhttp:(\/\/. +\.jpg) to group by () $1Gets its inner thing [] representation or ^ represents the beginning of $ means the end of the G represents the global \d{4}[/-]\d{2}[/-]\d{2}\w represents a word character literal:varreg=/\bis\b/g; Constructor:varreg=NewREGEXP (' \\bis\\b ',' G '); Modifiers:g:GlobalFull-text search; Do not add, search to the first match stopI: Ignore CaseIgnores case, does not add, case-sensitive m:multiple lines multi-line search sub-character class:' a1b1c1d3f3 '. replace (/[abc]/g,' X ') Character class inversion:' a1b1c1d3f3 '. replace (/[^abc]/g,' X ') Scope class:' A1B1C1D1F1E1ASD '. replace (/[a-z]/g,' Q '); Many range classes:' A1b1c1d1f1e1asdabgs123bgjs '. replace (/[a-za-z]/g,' Q '), when selecting multiple range classes, you need to match "-", then add "-" at the end:' 2010-07-08 '. replace (/[0-9-]/g,' A '); Booking class: Matches a ab+ number + any character string: ab\d. Boundary:' This was a boy '. replace (/\bis\b/g,' 0 ') @ Start:' @[email protected]@ '. replace (/^@./g,' Q ') @ end:' @[email protected]@ '. replace (/[email protected]$/g,' Q ') Multi-line matching:' @123@456@789 '. replace (/^@\d/gm,' X 'Quantifier: \d represents a digital \d??0or a \d+ + represents one or more \d{3} represents three \d{3,5} represents three to five \d{3,} indicates that at least one occurrence3Times \d* * indicates0To any of the regular expression greedy patterns:' 12345678 '. replace (/\d{3,6}/g,"A"); Non-greedy mode (add a "?" later) You can do it):' 123456789 '. Match (/\d{3,5}?/gGroup' A1b1c1d1 '. replace (/[a-z]\d{3}/g,"X")"A1B1C1D1"' A1b1c1d1 '. replace (/([a-z]\d) {3}/g,"X")"Xd1"Or:' AbcdEf '. replace (/abcd| Ef/g,' X ');"XX"' ABCDEFABABEF '. replace (/ab (cd|ab) ef/g,' X ');"XX"Reverse reference:' 2016-12-21 '. replace (/(\d{4})-(\d{2})-(\d{2})/g,' $2-$3-$1 ')"12-21-2016"Forward (a number after the preceding word character):' a2*3 '. replace (/\w (? =\d)/g,' X ')"X2*3"' A2*34v8 '. replace (/\w (? =\d)/g,' X ')"x2*x4x8"' A2*34VV '. replace (/\w (? =\d)/g,' X ')"X2*X4VV"' A2*34VV '. replace (/\w (?! \d)/g,' X ')"Ax*3xxx"Object properties:g:GlobalFull-text search; Do not add, search to the first match stopI: Ignore CaseIgnoring case, not adding, case sensitive m:multiple lines multi-line search lastindex: The next location of the last character of the current expression match content source: text string of the regular expression test method:varreg1=/\w/;varReg2=/\w/g; Reg1.test (' A ');trueReg1.test (' $ ');falseReg2.test (' A ');trueReg2.test (' A ');falseReg2.test (' A ');trueReg2.test (' A ');false while(Reg2.test (' AB ')){Console. log (reg2.lastindex);} Exec method: Non-global invocation:varreg3=/\d (\w) \d/;varreg4=/\d (\w) \d/g;varts=' 1a2b3c4d5e ';varRet=reg3.exec (TS);Console. log (Reg3.lastindex +' \ t '+ret.index+' \ t '+ ret.tostring ());Console. log (Reg3.lastindex +' \ t '+ret.index+' \ t '+ ret.tostring ()); while(Ret=reg4.exec (TS)) {Console. log (Reg4.lastindex +' \ t '+ret.index+' \ t '+ ret.tostring ());}0 0 1A2,a0 0 1A2,a3 0 1A2,a7 4 3C4,c non-global lastindex does not take effect ToString ()): The first regular gets the field, the second regular in the grouped field under global: The first number: After the first acquisition, Position of next character second number: Gets the third number that matches the regular match from the first character: The field that was obtained in the second regular, the field string object method for the group in the secondary rule:varreg3=/\d (\w) \d/;varreg4=/\d (\w) \d/g;varts=' 1a2b3c4d5e ';varRet=ts.match (REG3);Console. log (ret);Console. log (Ret.lastindex +' \ t '+ret.index+' \ t '); Ret=ts.match (REG4);varRet=ts.match (REG4);Console. log (ret);Console. log (Ret.lastindex +' \ t '+ret.index+' \ t ');' A1b2c3d4 '. Split (/\d/g)
JavaScript regular expressions for the Web front-end