概述
RegExp.prototype 属性表示 RegExp 构造函数的原型对象。
描述
查看 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 - 是否开启粘滞匹配。
Properties inherited from
Object:
方法
-
RegExp.prototype.exec() - 在目标字符串中执行一次正则匹配操作。
-
RegExp.prototype.test() - 测试当前正则是否能匹配目标字符串。
-
RegExp.prototype.toSource() -
返回一个字符串,其值为该正则对象的字面量形式。覆盖了
Object.prototype.toSource方法. -
RegExp.prototype.toString() -
返回一个字符串,其值为该正则对象的字面量形式。覆盖了
Object.prototype.toString()方法。
Methods inherited from
Object:
规范
| Specification | Status | Comment |
|---|---|---|
| ECMAScript 1st Edition. Implemented in JavaScript 1.1 | Standard | Initial definition. |
| ECMAScript 5.1 (ECMA-262) RegExp |
Standard | |
| ECMAScript 2015 (6th Edition, ECMA-262) RegExp.prototype |
Standard |
浏览器兼容性
We're converting our compatibility data into a machine-readable JSON format. This compatibility table still uses the old format, because we haven't yet converted the data it contains.
Find out how you can help!
| 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) |
相关链接
- Regular Expressions chapter in the JavaScript Guide
RegExpFunction.prototype