非标
此特征是非标准的,且不在标准轨道中。不要在面向 Web 的生产站点中使用它:它不适用于每个用户。实现之间可能存在大的不兼容性,且行为将来可能改变。

The non-standard leftContext property is a static and read-only property of regular expressions that contains the substring preceding the most recent match. RegExp.$` is an alias for this property.

描述

leftContext property is static, it is not a property of an individual regular expression object. Instead, you always use it as RegExp.leftContext or RegExp['$`'] .

The value of the leftContext 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 template string in that case and a SyntaxError is thrown. Use the bracket notation for property access .

范例

Using leftContext and $`

var re = /world/g;
re.test('hello world!');
RegExp.leftContext; // "hello "
RegExp['$`'];       // "hello "
					

规范

规范
Legacy RegExp features in JavaScript

浏览器兼容性

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. 更新 GitHub 上的兼容性数据
Desktop Mobile Server
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet Node.js
RegExp.leftContext ( $` ) 非标 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

图例

完整支持

完整支持

非标。预期跨浏览器支持较差。

另请参阅

元数据

  • 最后修改: