V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
mashirozx

Safari 上不支持向后匹配的正则表达式,请教替代方法

  •  
  •   mashirozx · Nov 24, 2022 · 1370 views
    This topic created in 1252 days ago, the information mentioned may be changed or developed.

    如下正则,在 Chrome 上 OK ,但是 Safari 上报 Invalid regular expression,看了一下原因是 Safari 不支持向后匹配 ((?<!),见 can i use

    如下是我的正则:

    /(?<!\/.*?)showLineNumbers(?:\{(\d+)})?/
    

    期望的效果如图:

    cc89c06c94b73a4b3b7956c0825a4654.png

    求一个不使用向后匹配表达式((?<!)的替代方法 🙏

    PS. 这个正则工具挺好用的: https://regex101.com

    mashirozx
        1
    mashirozx  
    OP
       Nov 24, 2022
    已解决,自问自答:

    export const reverseString = s => s?.split('').reverse().join('');

    const match = reverseString(meta).match(
    /(?:\}(\d+){)?srebmuNeniLwohs(?!(.*)(\/))/
    )

    reverseString(match[1])
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3998 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 04:11 · PVG 12:11 · LAX 21:11 · JFK 00:11
    ♥ Do have faith in what you're doing.