Open In App
Related Articles

JavaScript RegExp toString() Method

Improve Article
Improve
Save Article
Save
Like Article
Like

The RegExp toString() Method in JavaScript is used to return the string value of the regular expression.

Syntax:  

RegExpObject.toString()

Example 1: This example returns the string value of the regular expression.  

Javascript




function geek() {
    let regex = new RegExp("[a-c]", "gi");
    let rex = regex.toString();
    console.log(rex);
}
geek()


Output

/[a-c]/gi

Example 2: This example returns the string value of the regular expression. 

Javascript




function geek() {
    let regex = /[a-k]/g;
    let rex = regex.toString();
    console.log(rex);
}
geek()


Output

/[a-k]/g

Supported Browsers: The browsers supported by RegExp toString() Method are listed below: 

  • Google Chrome 1 and above
  • Edge 12 and above
  • Firefox 1 and above
  • Opera 5 and above
  • Safari 1 and above

We have a complete list of Javascript RegExp expressions, to check those please go through this JavaScript RegExp Complete Reference article.

We have a Cheat Sheet on Javascript where we covered all the important topics of Javascript to check those please go through Javascript Cheat Sheet-A Basic guide to JavaScript.  

Whether you're preparing for your first job interview or aiming to upskill in this ever-evolving tech landscape, GeeksforGeeks Courses are your key to success. We provide top-quality content at affordable prices, all geared towards accelerating your growth in a time-bound manner. Join the millions we've already empowered, and we're here to do the same for you. Don't miss out - check it out now!

Last Updated : 02 Jun, 2023
Like Article
Save Article
Previous
Next
Similar Reads
Complete Tutorials