JavaScript Regular expression pattern matching (2)--Grouping pattern matching

Source: Internet
Author: User

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

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.