The source Property in JavaScript is used to return the text of the text of the RegExp pattern.
Syntax:
RegExpObject.source
Where RexExp refers to the regular expression.
Example : This example returns the text “Geek”.
<!DOCTYPE html> <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> <script> function geek() { var patt1 = /Geek/gi; var res = "Text of RegExp is: " + "<b>" + patt1.source + "</b>"; document.getElementById("app").innerHTML = res ; </script> </body> </html> |
chevron_right
filter_none
Output:
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
Recommended Posts:
- 6 Most Popular and Open-Source Machine Learning JavaScript Frameworks
- Top 5 Free Open-Source JavaScript Frameworks For Web Developers in 2020
- CSS | border-image-source Property
- HTML | DOM Source Object
- HTML | <source> type Attribute
- HTML | <source> src Attribute
- HTML | <source> Tag
- HTML | <source> media Attribute
- HTML | <source> srcset Attribute
- How to hide “Image not found” icon when source image is not found?
- Top 5 Free and Open-Source Version Control Tools in 2020
- D3.js ribbon.source() Function
- How to add section that is quoted from another source using HTML ?
- How to Change Image Source URL using AngularJS ?
- JavaScript Course | Understanding Code Structure in JavaScript
- Introduction to JavaScript Course | Learn how to Build a task tracker using JavaScript
- JavaScript Course | Loops in JavaScript
- JavaScript Course | Data Types in JavaScript
- JavaScript Course | Printing Hello World in JavaScript
- JavaScript Course | Logical Operators in JavaScript
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.


