ES6 - RegExp source


Advertisements

source is a read-only string property of RegExp objects. It contains the text of the RegExp pattern. This text does not include the delimiting slashes used in regular-expression literals, and it does not include the "g", "i", and "m" attributes.

Syntax

RegExpObject.source         

Return Value

Returns the text used for pattern matching.

Example

var str = "Javascript is an interesting scripting language"; 
var re = new RegExp( "script", "g" );      
re.test(str); 
console.log("The regular expression is : " +  re.source);

Output

The regular expression is : script      
es6_regexp.htm
Advertisements