亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

ESLint 和lookbehind 斷言

ESLint 和lookbehind 斷言

開心每一天1111 2023-07-20 10:52:26
我有一個正則表達式,其中包含 ESLint 似乎不認為有效的后向斷言。然而,前瞻斷言是可以的。我可以使用最新版本的 ESLint(我使用過在線演示)以及非常簡單且人為的示例來重現此問題。前瞻斷言:匹配b(且僅b)如果后跟d:'bd'.match(/b(?=d)/) //=> ['b'] 'be'.match(/b(?=d)/) //=> nullESLint 識別/b(?=d)/為有效的正則表達式:Lookbehind 斷言:匹配b(且僅b)如果前面是a:'ab'.match(/(?<=a)b/) //=> ['b'] 'eb'.match(/(?<=a)b/) //=> nullESLint 無法識別/(?<=a)b/為有效的正則表達式:問題:我的正則表達式有什么問題導致 ESLint 抱怨?上面演示中使用的 ESLint 配置:{    "parserOptions": {        "ecmaVersion": 5,        "sourceType": "script",        "ecmaFeatures": {}    },    "rules": {        "constructor-super": 2,        "for-direction": 2,        "getter-return": 2,        "no-async-promise-executor": 2,        "no-case-declarations": 2,        "no-class-assign": 2,        "no-compare-neg-zero": 2,        "no-cond-assign": 2,        "no-const-assign": 2,        "no-constant-condition": 2,        "no-control-regex": 2,        "no-debugger": 2,        "no-delete-var": 2,        "no-dupe-args": 2,        "no-dupe-class-members": 2,        "no-dupe-else-if": 2,        "no-dupe-keys": 2,        "no-duplicate-case": 2,        "no-empty": 2,        "no-empty-character-class": 2,        "no-empty-pattern": 2,        "no-ex-assign": 2,        "no-extra-boolean-cast": 2,        "no-extra-semi": 2,        "no-fallthrough": 2,        "no-func-assign": 2,        "no-global-assign": 2,        "no-import-assign": 2,        "no-inner-declarations": 2,        "no-invalid-regexp": 2,        "no-irregular-whitespace": 2,        "no-misleading-character-class": 2,        "no-mixed-spaces-and-tabs": 2,        "no-new-symbol": 2,        "no-obj-calls": 2,        "no-octal": 2,        "no-prototype-builtins": 2,        "no-redeclare": 2,        "no-regex-spaces": 2,        "no-self-assign": 2,        "no-setter-return": 2,        "no-shadow-restricted-names": 2,        "no-sparse-arrays": 2,        "no-this-before-super": 2,        "no-undef": 2,    },    "env": {}}javascript正則表達式埃斯林特
查看完整描述

1 回答

?
qq_花開花謝_0

TA貢獻1835條經驗 獲得超7個贊

您可以參考指定解析器選項

ecmaVersion- 設置為 3、5(默認)、6、7、8、9、10、11 或 12 以指定要使用的 ECMAScript 語法版本。您還可以設置為 2015 年(與 6 相同)、2016 年(與 7 相同)、2017 年(與 8 相同)、2018 年(與 9 相同)、2019 年(與 10 相同)、2020 年(與 11 相同)或 2021 年(與 12) 相同,使用基于年份的命名。

如您所見,默認值為5,表示僅支持 ES5。Lookbehinds符合 ECMAScript 2018,因此您需要確保ecmaVersion至少設置為9

"parserOptions": {

? ? ? ? "ecmaVersion": 9,

? ? ? ? "sourceType": "script",

? ? ? ? "ecmaFeatures": {}

? ? },


查看完整回答
反對 回復 2023-07-20
  • 1 回答
  • 0 關注
  • 176 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號