1 varpattern=/google{4,8}$/;//{4,8}$ Indicates the end of the match 4-8 times2 varStr= ' googleeeeeeeee ';//4-8 times for e3 Alert (pattern.test (str));4 5 varpattern=/(google) {4,8}$/;//grouping, which can be seen as a character6 varStr= ' Googlegooglegooglegoogle ';//represents Google 4-8 times7 Alert (pattern.test (str));8 9 varPATTERN=/6 (. *) 6/;//match any character between 6 6Ten varStr= ' This is a 6google6 '; One Alert (pattern.test (str)); A - varPATTERN=/6 (. *) 6/; - varStr= ' This is a 6google6 '; the pattern.test (str); -alert (regexp.$1);//regexp.$1 represents the matching word for the first group in the Get pattern - - varPATTERN=/6 (. *) 6/; + varStr= ' This is a 6google6 '; -document.write (str.replace (Pattern, ' <strong>123<strong> '));//replace the specified string + A varPATTERN=/6 (. *) 6/; at varStr= ' This is a 6baidu6 '; -document.write (str.replace (Pattern, ' <strong>$1<strong> '));//$ = Group Gets the string to which the string is matched - - varpattern=/(. *) \s (. *)/; - varStr= ' Google Baidu '; -Alert (str.replace (Pattern, ' $ $ '));//Position Exchange
JavaScript Regular expression pattern matching (2)--Grouping pattern matching