[removed] negative lookbehind equivalent?

前端 未结 12 1516
南旧
南旧 2020-11-21 05:47

Is there a way to achieve the equivalent of a negative lookbehind in javascript regular expressions? I need to match a string that does not start with a specific set of cha

12条回答
  •  野性不改
    2020-11-21 06:21

    Lookbehind Assertions got accepted into the ECMAScript specification in 2018.

    Positive lookbehind usage:

    console.log(
      "$9.99  €8.47".match(/(?<=\$)\d+(\.\d*)?/) // Matches "9.99"
    );

    Negative lookbehind usage:

    console.log(
      "$9.99  €8.47".match(/(?

    Platform support:

    • ✔️ V8
      • ✔️ Google Chrome 62.0
      • ✔️ Microsoft Edge 79.0
      • ✔️ Node.js 6.0 behind a flag and 9.0 without a flag
      • ✔️ Deno (all versions)
    • ✔️ SpiderMonkey
      • ✔️ Mozilla Firefox 78.0
提交回复
热议问题