RegExp.leftContext ($`)

非标准: 该特性是非标准的,请尽量不要在生产环境中使用它!

leftContext 非标准属性是正则表达式的静态和只读属性,含有最新匹配的左侧子串。 RegExp.$` 是这个属性的别名。

语法

RegExp.leftContext
RegExp['$`']

描述

leftContext 属性是静态的,不是正则表达式独立对象的属性。反之,你应始终将其使用为 RegExp.leftContext 或者 RegExp['$`']

leftContext 属性的值是只读的,并且会在匹配成功时修改。

你不能使用属性访问器 (RegExp.$`) 来使用简写的别名,因为解析器在这里会将其看做模板字符串的开始,并抛出 SyntaxError 。使用 方括号符号来访问属性。

示例

使用 leftContext$`

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

规范

非标准。并不是任何现行规范的一部分。

浏览器兼容性

Report problems with this compatibility data on GitHub
desktopmobileserver
Chrome
Edge
Firefox
Opera
Safari
Chrome Android
Firefox for Android
Opera Android
Safari on iOS
Samsung Internet
WebView Android
WebView on iOS
Deno
Node.js
RegExp.leftContext ($`)
Deprecated

Legend

Tip: you can click/tap on a cell for more information.

Full support
Full support
Deprecated. Not for use in new websites.

参见