1 varPattern=/g. gle/;//dot symbol to match any character except line break2 varStr= ' G78gle ';3 Alert (pattern.test (str));4 5 6 varpattern=/go*gle/;//o*, representing 0 or more o7 varStr= ' Goooooooooooogle ';8 Alert (pattern.test (str));9 Ten varpattern=/go+gle/;//o+, indicating one or more o One varStr= ' Gogle '; A Alert (pattern.test (str)); - - the varpattern=/go?gle/;//O, indicates 0 or 1 o - varStr= ' Google '; - Alert (pattern.test (str)); - + varpattern=/go{2,4}gle/;//o{2,4}, which indicates matching o 2-4 times, including 2 and 4 - varStr= ' Google '; + Alert (pattern.test (str)); A at - varpattern=/go{3}gle/;//o{2,4}, indicating that matching o can only be 3 times - varStr= ' Google '; - Alert (pattern.test (str)); - - in varpattern=/go{3,}gle/;//o{2,4}, indicating a match O3 or more than 3 times - varStr= ' Google '; to Alert (pattern.test (str)); + - varpattern=/[a-z]oogle/;//[A-z] represents 26 lowercase letters, any one can match the varStr= ' Google '; * Alert (pattern.test (str)); $ Panax Notoginseng varpattern=/[0-9]*oogle/;//[0-9]*, 0 times one or more times - varStr= ' 4444444oogle '; the Alert (pattern.test (str)); + A varpattern=/[a-za-z0-9]oogle/;//[a-za-z0-9] means case a-za-z0-9 the varStr= ' 9oogle '; + Alert (pattern.test (str)); - $ $ varpattern=/[^0-9]oogle/;//[^0-9] represents any character that is not 0-9 - varStr= ' _oogle '; - Alert (pattern.test (str)); the - varpattern=/^[0-9]oogle/;//This ^ symbol is the first character match that is added to/followed instead of []Wuyi varStr= ' 1oogle '; the Alert (pattern.test (str)); - Wu varpattern=/^[0-9]+oogle/;//this ^ symbol, which is added in/behind instead of [], means that it can match one or more - varStr= ' 11111oogle '; About Alert (pattern.test (str)); $ - varpattern=/\woogle/;//\w to match any alphanumeric and underscore - varStr= ' Woogle '; - Alert (pattern.test (str)); A + varpattern=/\woogle/;//\w to match non-arbitrary alphanumeric and underscore the varStr= ' Woogle '; - Alert (pattern.test (str)); $ the varpattern=/\doogle/;//\d said [0-9] the varStr= ' 2oogle '; the Alert (pattern.test (str)); the - varpattern=/\doogle/;//\d = Non-[0-9] in varStr= ' Aoogle '; the Alert (pattern.test (str)); the About varpattern=/^[a-z]oogl[0-9]$/;//^ Force first match $ forced tail match the varStr= ' Aoogle '; the Alert (pattern.test (str)); the + varpattern=/goo\sgle/;//\s indicates a space match - varStr= ' Goo gle '; the Alert (pattern.test (str));Bayi the varpattern=/google\b/;//\b Indicates whether the boundary is reached the varStr= ' Googled '; - Alert (pattern.test (str)); - the varpattern=/google|baidu|bing/;//| Indicates whether the pattern is matched or selected the varStr= ' Baidu '; theAlert (Pattern.test (str));
JavaScript Regular expression pattern matching (1)--Basic character matching