Use of RegExp Object in JavaScript

In this article I am going to explain about RegExp object in JavaScript.
  • 2115

JavaScript RegExp Object

In JavaScript Regular Expiration object use for describe pattern of character. Regular Expiration perform perform pattern-matching and "search-and-replace" functions on text.  In pattern-maching simple pattern can be one single character and more complicated pattern can consist of more characters, and can be used for parsing, format checking, substitution and more. There are several properties and method of Regular Expiration object.

RegExp object properties

  • I - Perform case sensitive matching.
  • G - Perform global matching.
  • M - Perform multiline matching

RegExp object method

  • Compile() - Compile a regular expiration
  • Exec() - Return first matching
  • Test() - Match in string and return true and false

Example:

In this example if  "e"  match in sentence then it will return true other wise it will return false

<html>

<head>

    <script type="text/javascript">

function Myfun() {

var patt1 = new RegExp("e");

document.write(patt1.test("How are you");

}

 

    </script>

</head>

<body>

    <button onclick="Myfun()">

        Click</button>

</body>

</html>

 

Output


 regu.gif

 

Further Readings

You may also want to read these related articles :here

Ask Your Question 

Got a programming related question? You may want to post your question here

Programming Answers here

Categories

More Articles

© 2020 DotNetHeaven. All rights reserved.