Open In App

JavaScript source Property

Last Updated : 03 Jan, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

The source Property in JavaScript is used to return the text of the RegExp pattern.

Syntax: 

RegExpObject.source

Where RexExp refers to the regular expression.

Example : This example returns the text “Geek”. 

html




<script>
    function geek() {
        var patt1 = /Geek/gi;
        var res="Text of RegExp is: " + "<b>" + patt1.source + "</b>";
        document.getElementById("app").innerHTML = res ;
    }
</script>
  
<h1 style="color:green">GeeksforGeeks</h1>
<h2>Source Property</h2>
<p>RegExp: /Geek/gi</p>
<button onclick=geek()>Click it!</button>
<p id="app"></p>


Output:

JavaScript source Property

JavaScript source Property

 

Supported Browsers: The browsers supported by JavaScript source Property are listed below:

  • Google Chrome
  • Apple Safari
  • Mozilla Firefox
  • Opera
  • Internet Explorer

Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads