📅  最后修改于: 2020-10-25 10:59:38             🧑  作者: Mango
toString()方法返回一个表示正则表达式的字符串。
RegExpObj.toString();
不适用
此方法返回表示给定对象的字符串。
var str = "";
var re = new RegExp( "","g" );
var result = re.toString(str);
document.write("
Returned value : " + result);
输出:
Returned value : /(?:)/g
document.write (new RegExp("a+b+c","g").toString());
document.write(new RegExp("
gt+yu").toString());
document.write(new RegExp("
abcd").toString());
document.write(new RegExp('
\\n', 'g').toString());
输出:
/a+b+c/g/
gt+yu//
abcd//
\n/g
var str = "scripting language";
var re = new RegExp( "script", "g" );
var result = re.toString(str);
document.write("Returned value : " + result);
re = new RegExp( "","g" );
var result = re.toString(str);
document.write("
Returned value : " + result);
输出:
Returned value : /script/g
Returned value : /(?:)/g