Open In App

JavaScript RegExp toString() Method

Last Updated : 02 Jun, 2023
Improve
Improve
Like Article
Like
Save
Share
Report

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.  


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

Similar Reads