非标
此特征是非标准的,且不在标准轨道中。不要在面向 Web 的生产站点中使用它:它不适用于每个用户。实现之间可能存在大的不兼容性,且行为将来可能改变。
The non-standard
rightContext
property is a static and read-only property of regular expressions that contains the substring following the most recent match.
RegExp.$'
is an alias for this property.
rightContext
property is static, it is not a property of an individual regular expression object. Instead, you always use it as
RegExp.rightContext
or
RegExp["$'"]
.
The value of the
rightContext
property is read-only and modified whenever a successful match is made.
You can not use the shorthand alias with the dot property accessor (
RegExp.$'
), because the parser expects a starting string in that case and a
SyntaxError
is thrown. Use the
bracket notation for property access
.
var re = /hello/g;
re.test('hello world!');
RegExp.rightContext; // " world!"
RegExp["$'"]; // " world!"
| 规范 |
|---|
| Legacy RegExp features in JavaScript |
| Desktop | Mobile | Server | |||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
RegExp.rightContext
(
$'
)
非标
|
Chrome 1 | Edge 12 | Firefox 1 | IE 5.5 | Opera 8 | Safari 3 | WebView Android 1 | Chrome Android 18 | Firefox Android 4 | Opera Android 10.1 | Safari iOS 1 | Samsung Internet Android 1.0 | nodejs Yes |
完整支持
非标。预期跨浏览器支持较差。
RegExp
RegExp.$1-$9
RegExp.input ($_)
RegExp.lastMatch ($&)
RegExp.lastParen ($+)
RegExp.leftContext ($`)
RegExp.prototype.dotAll
RegExp.prototype.flags
RegExp.prototype.global
RegExp.prototype.ignoreCase
RegExp.prototype.multiline
RegExp.prototype.source
RegExp.prototype.sticky
RegExp.prototype.unicode
RegExp.rightContext ($')
RegExpInstance.lastIndex
get RegExp[@@species]
Function
Object
Object.prototype.__defineGetter__()
Object.prototype.__defineSetter__()
Object.prototype.__lookupGetter__()
Object.prototype.__lookupSetter__()
Object.prototype.hasOwnProperty()
Object.prototype.isPrototypeOf()
Object.prototype.propertyIsEnumerable()
Object.prototype.toLocaleString()
Object.prototype.toSource()
Object.prototype.toString()
Object.prototype.valueOf()
Object.setPrototypeOf()