RegExp.prototype
RegExp.prototype 属性表示 RegExp构造函数的原型对象。
| RegExp.prototype的属性的属性特性 |
|:----|
| Writable | no |
| Enumerable | no |
| Configurable | no |
描述
查看 RegExp 了解更多关于 RegExp 实例的说明。
RegExp 实例继承 RegExp.prototype。修改该原型对象上的属性或方法会影响到所有的 RegExp 实例。
属性
注意,RegExp 对象的几个属性既有完整的长属性名,也有对应的类 Perl 的短属性名。两个属性都有着同样的值。JavaScript 的正则语法就是基于 Perl 的。
RegExp.prototype.constructor创建该正则对象的构造函数。
RegExp.prototype.global是否开启全局匹配,也就是匹配目标字符串中所有可能的匹配项,而不是只进行第一次匹配。
RegExp.prototype.ignoreCase在匹配字符串时是否要忽略字符的大小写。
RegExp.prototype.lastIndex下次匹配开始的字符串索引位置。
RegExp.prototype.multiline是否开启多行模式匹配(影响 ^ 和 $ 的行为)。
RegExp.prototype.source正则对象的源模式文本。
RegExp.prototype.sticky是否开启粘滞匹配。
方法
RegExp.prototype.exec()在目标字符串中执行一次正则匹配操作。
RegExp.prototype.test()测试当前正则是否能匹配目标字符串。
RegExp.prototype.toSource()返回一个字符串,其值为该正则对象的字面量形式。覆盖了Object.prototype.toSource 方法.
RegExp.prototype.toString()返回一个字符串,其值为该正则对象的字面量形式。覆盖了Object.prototype.toString() 方法。
规范
Specification | Status | Comment |
|---|---|---|
ECMAScript 3rd Edition (ECMA-262) | Standard | Initial definition. Implemented in JavaScript 1.1. |
ECMAScript 5.1 (ECMA-262)The definition of 'RegExp' in that specification. | Standard | |
ECMAScript 2015 (6th Edition, ECMA-262)The definition of 'RegExp.prototype' in that specification. | Standard | Added flags, sticky and unicode properties. |
ECMAScript Latest Draft (ECMA-262)The definition of 'RegExp.prototype' in that specification. | Draft | |
浏览器兼容性
Feature | Chrome | Edge | Firefox (Gecko) | Internet Explorer | Opera | Safari |
|---|---|---|---|---|---|---|
Basic support | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |
Feature | Android | Chrome for Android | Edge | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
|---|---|---|---|---|---|---|---|
Basic support | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) | (Yes) |
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com

