javascript regex - look behind alternative?

前端 未结 6 1989
时光取名叫无心
时光取名叫无心 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:25

    This is an equivalent solution to Tim Pietzcker's answer (see also comments of same answer):

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

    It means, match *.js except *filename.js.

    To get to this solution, you can check which patterns the negative lookbehind excludes, and then exclude exactly these patterns with a negative lookahead.

提交回复
热议问题