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.