JavaScript RegExp source Property

The JavaScript source properrty is used to get the text/string of the Regular Expression pattern. For example:

HTML with JavaScript Code
<!DOCTYPE html>
<html>
<body>

   <p id="res"></p>

   <script>
      let myString = "I live in St. Louis";
      let myPattern = /is/gi;
      document.getElementById("res").innerHTML = myPattern.source;
   </script>
   
</body>
</html>
Output

JavaScript source Syntax

The syntax of source property in JavaScript is:

RegExpObj.source

It returns a string representing the textual part of the specified regular expression pattern.

JavaScript Online Test


« Previous Tutorial Next Tutorial »