javascript regex - look behind alternative?

前端 未结 6 1983
时光取名叫无心
时光取名叫无心 2020-11-22 05:44

Here is a regex that works fine in most regex implementations:

(?

This matches .js for a string which ends with .js exc

6条回答
  •  夕颜
    夕颜 (楼主)
    2020-11-22 06:33

    ^(?!filename).+\.js works for me

    tested against:

    • test.js match
    • blabla.js match
    • filename.js no match

    A proper explanation for this regex can be found at Regular expression to match string not containing a word?

    Look ahead is available since version 1.5 of javascript and is supported by all major browsers

    Updated to match filename2.js and 2filename.js but not filename.js

    (^(?!filename\.js$).).+\.js

提交回复
热议问题