Javascript uses a regular expression to match the same word as the first letter and the last letter. js expression

Source: Internet
Author: User

Javascript uses a regular expression to match the same word as the first letter and the last letter. js expression

This example describes how to use a regular expression in JavaScript to match the same word as the last letter. Share it with you for your reference. The specific implementation method is as follows:

Copy codeThe Code is as follows: <Head>
<Script type = "text/javascript">
// Subexpression example: Find the word with the same first letter and last letter
Function t1 (){
Var con = document. getElementsByName ('content') [0]. value;
Var reg =/\ B (\ w) \ w * \ 1 \ B/g;
Alert (con. match (reg ));
}
</Script>
</Head>
<Body>
<Textarea rows = "5" cols = "30" name = "content"> </textarea> <br/>
<Button onclick = "t1 ();"> the first and last letters of the same word </button> <br/>
</Body>
</Html>

Note: The subexpression can be referenced in the following two ways:
First: If it is referenced inside the expression, use \ n;
Type 2: use $ n as a variable for reference elsewhere.

I hope this article will help you learn javascript regular expressions.

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.