Skip to content
Related Articles

Related Articles

Improve Article

JavaScript | source Property

  • Last Updated : 30 Apr, 2019

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


Where RexExp refers to the regular expression.
Example : This example returns the text “Geek”.

<!DOCTYPE html>
    <body style="text-align:center">
        <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>
        function geek() {
            var patt1 = /Geek/gi;
            var res 
            = "Text of RegExp is: " +  "<b>" + patt1.source + "</b>";
          document.getElementById("app").innerHTML =  res ;

Before clicking the button:
After clicking the button:
Supported Browsers: The browsers supported by JavaScript source Property are listed below:

  • Google Chrome
  • Apple Safari
  • Mozilla Firefox
  • Opera
  • Internet Explorer
My Personal Notes arrow_drop_up
Recommended Articles
Page :