Negative lookahead Regular Expression

前端 未结 7 910
后悔当初
后悔当初 2020-11-27 14:00

I want to match all strings ending in \".htm\" unless it ends in \"foo.htm\". I\'m generally decent with regular expressions, but negative lookaheads have me stumped. Why

7条回答
  •  挽巷
    挽巷 (楼主)
    2020-11-27 14:38

    Like Renesis mentioned, "lookbehind" is not supported in JavaScript, so maybe just use two regexps in combination:

    !/foo\.htm$/i.test(teststring) && /\.htm$/i.test(teststring)
    

提交回复
热议问题