toString() 返回一个表示该正则表达式的字符串。
regexObj.toString()
无
RegExp 对象覆盖了 Object 对象的 toString() 方法,并没有继承 Object.prototype.toString()。对于 RegExp 对象,toString 方法返回一个该正则表达式的字符串形式。
toString下例输出 RegExp 对象的字符串值:
myExp = new RegExp("a+b+c");
alert(myExp.toString()); // 显示 "/a+b+c/"
foo = new RegExp("bar", "g");
alert(foo.toString()); // 显示 "/bar/g"
| Specification | Status | Comment |
|---|---|---|
| ECMAScript 3rd Edition. Implemented in JavaScript 1.1 | Standard | Initial definition. |
| ECMAScript 5.1 (ECMA-262) RegExp.prototype.toString |
Standard | |
| ECMAScript 2015 (6th Edition, ECMA-262) RegExp.prototype.toString |
Standard |
| Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|
| Basic support | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |
| Feature | Android | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|---|
| Basic support | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |