RegExp.prototype.toString()
Baseline
Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since 2015年7月.
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 |
|---|
| ECMAScript® 2026 Language Specification> # sec-regexp.prototype.tostring> |
浏览器兼容性
Loading…