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.


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

      <title>JavaScript RegExp source Property</title>

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