JavaScript Regular expression pattern matching (1)--Basic character matching

Source: Internet
Author: User

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

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.