What is the role of source RegExp property in JavaScript?

HTMLJavascriptProgramming Scripts

The source RegExp property in JavaScript is a read-only string property of RegExp objects. It contains the text of the RegExp pattern. This text does not include the delimiting slashes used in regular-expression literals, and it does not include the "g", "i", and "m" attributes.

Example

You can try to run the following code to learn how to implement source RegExp property in JavaScript −

<html>
   <head>
      <title>JavaScript RegExp source Property</title>
   </head>

   <body>
      <script>
         var str = "JavaScript is an interesting scripting language";
         var re = new RegExp( "script", "g" );
         re.test(str);
         
         document.write("The regular expression is : " + re.source);
      </script>
   </body>
</html>
raja
Published on 26-Feb-2018 11:38:17
Advertisements