javascript - `replace()` 函数版本中的命名捕获组
问题描述
我注意到您实际上可以在替换回调中传递您命名的捕获组:
'Yoda said "fear leads to anger."'.replace(
/(?<pre>\b\w+\b)(?<betwixt> leads to )(?<post>\b\w+\b)/,
(...args) => {
let [{pre, betwixt, post}] = args.slice(-1);
let ani = {fear:'anger',anger:'hate',hate:'suffering'};
return `${ani[pre]}${betwixt}${ani[post]}`;
}
)
结果在Yoda said "anger leads to hate."
. 至少在铬。
我的问题是这是在哪里定义的?它绝对看起来不规范。
它似乎始终是最后一个参数,在string
.
我想知道它是一个即将推出的标准,还是我偶然发现的 chrome 开发人员临时有的东西,它会消失:(
解决方案
推荐阅读
- r - 用于下载 2020 年 COVID-19 隔离期间免费发布的所有 Springer 书籍的 R 脚本
- microsoft-graph-api - 如何使用 Microsoft Graph Api 和应用程序访问权限从 SharePoint 获取 SitePage 的缩略图?
- python-3.x - 生成 ande 评估 200 个法线并减少它们
- kubernetes - Pod 中的容器尝试联系 Kubernetes API 服务器时出现 SocketTimeoutException
- javascript - 滚动崩溃时的导航栏更改
- reactjs - 反应状态更新不反映
- flutter - 使用 AuthController 传递用户 ID
- python - 如何根据最小值对行进行排序并在 Pandas 中替换它们?
- javascript - “.value”是输入元素的属性吗?
- tomcat8 - javamelody - 始终在 tomcat 临时文件夹的相对路径中存储文件