<!doctype html>window.onload=function() {tdregexp (); } <!--regular expression repeat match--functionTestregexp () {varPattren=/g. gle/;//. Match all characters except line break varpattren1=/g.*gle/;//. * Match 0 or more varpattren2=/g.+gle/;//. + Match at least one varPattren3=/g.? gle/;// .? Match 0 or one varpattren4=/g.{1,5}gle/;// . {M,n} matches at least m maximum of n varpattren5=/g.{5}gle/;// . {m} matches m varpattren6=/g.{5,}gle/;// . {m,} matches m or more m varStr= "Goooooogle"; varfalg=pattren6.test (str); alert (FALG); } <!--regular expression character matching--functionTeststrregexp () {varpattren1=/[a-z]oogle/i;//[A-z] matches 26 lowercase letters Any one I means case insensitive varpattren2=/\doogle/;//\d Match 10 digits any one varpattren3=/[0-9]oogle/;//[0-9] match 10 digits of any one varpattren4=/[0-9]*oogle/;//[0-9]* matches 10 digits any one 0 or more times varpattren5=/[a-za-z0-9]oogle/;//[a-za-z0-9]* match matches 26 letters or 10 digits of any one varpattren6=/[^0-9]oogle/;//[^0-9] matches any one of the non-10 digits varpattren7=/^[0-9]oogle/;//^[0-9] matches any one of 10 numbers starting with the first string varpattren8=/\woogle/;//\w matches Alpha-numeric and _ varpattren9=/\woogle/;//\w matches non-alphanumeric and _ varpattren10=/\doogle/;//\d matches a non-10 number of any one varpattren11=/google$/;//$ represents a match from the last startvarstr= "Google adasd"; varfalg=pattren11.test (str); alert (FALG); } <!--regular expression special character matching--functionTeststr2regexp () {varpattren1=/go\sogle/;//\s Matching spaces varpattren2=/google\b/;//\b Match reaches character channeling boundary varpattren3=/google|baidu|soso| ie/;//| match or select mode varpattren4=/(google) {2,5}/;//() indicates that the grouping matches the string in parentheses as a character varStr= "Google"; varfalg=pattren3.test (str); alert (FALG); } functionStaticregexp () {varPattren1=/g (. *) g/;//\s Matching spaces varStr= "This a Google"; Pattren1.test (str); varflag=regexp.$1;//Get matching charactersalert (flag); //—————————————————————————— varPattren2=/\s (. *) \s/; varStr= "This Google"; varHtml=str.replace (Pattren2, "); document.write (HTML); //——————— Position Exchange ——————————————————— varpattren3=/(. *) \s (. *)/; varStr= "This Google"; varHtml=str.replace (Pattren3, "); document.write (HTML); } functionTdregexp () {//——————— greedy mode ——————————————————— varPATTERN1=/8 (. *) 8/G; varStr= "8google8 8google8 8google8 8google8"; varHtml=str.replace (PATTERN1, "<span>$1</span><br>"); document.write (HTML);//results google8 8google8 8google8 8google //——————— lazy Mode ——————————————————— varPATTERN2=/8 (. *?) 8/ G//g turn on global varStr= "8google8 8google8 8google8 8google8"; varHtml=str.replace (pattern2, "<span>$1</span>"); document.write (HTML);//results google google google google } </script>JS Regular expression