无涯教程-RegExp.prototype.source函数

51 阅读1分钟

source是RegExp对象的只读字符串属性。该文本不包含在正则表达式文字中使用的定界斜杠,也不包含" g"," i"和" m"属性。

RegExp.prototype.source - 语法

RegExpObject.source         

RegExp.prototype.source - 返回值

返回用于模式匹配的文本。

RegExp.prototype.source - 示例

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);

运行上面代码输出

The regular expression is : script      

参考链接

www.learnfk.com/es6/es6-reg…