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 July 2015.
概述
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® 2025 Language Specification # sec-regexp.prototype.tostring |
浏览器兼容性
Report problems with this compatibility data on GitHubdesktop | mobile | server | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
toString | ||||||||||||||
Line breaks and slashes are escaped |
Legend
Tip: you can click/tap on a cell for more information.
- Full support
- Full support
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.