非标准
该特性是非标准的,请尽量不要在生产环境中使用它!
rightContext 非标准属性是正则表达式的静态和只读属性,含有最新匹配的右侧子串。 RegExp.$' 是这个属性的别名。
语法
RegExp.rightContext
RegExp["$'"]
描述
rightContext 属性是静态的,不是正则表达式独立对象的属性。反之,你应始终将其使用为 RegExp.rightContext 或者 RegExp["$'"]。
rightContext 属性的值是只读的,并且会在匹配成功时修改。
你不能使用属性访问器(RegExp.$')来使用简写的别名,因为解析器在这里会将其看做字符串的开始,并抛出 SyntaxError。使用 方括号符号来访问属性。
示例
使用 rightContext 和 $'
var re = /hello/g;
re.test('hello world!');
RegExp.rightContext; // " world!"
RegExp["$'"]; // " world!"
规范
非标准。并不是任何现行规范的一部分。
浏览器兼容性
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) |