ES6 - RegExp toString()


Advertisements

The toStringmethod returns a string representation of a regular expression in the form of a regular-expression literal.

Syntax

RegExpObject.toString();            

Return Value

Returns the string representation of a regular expression.

Example

var str = "Javascript is an interesting scripting language"; 
var re = new RegExp( "script", "g" ); 
var result = re.toString(str); 
console.log("Test 1 - returned value : " +  result);  
re = new RegExp( "/", "g" ); 

var result = re.toString(str); 
console.log("Test 2 - returned value : " +  result) 

Output

Test 1 - returned value : /script/g 
Test 2 - returned value : /\//g    
es6_regexp.htm
Advertisements