Negative lookahead Regular Expression

前端 未结 7 880
后悔当初
后悔当初 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:59

    String.prototype.endsWith (ES6)

    console.log( /* !(not)endsWith */
    
        !"foo.html".endsWith("foo.htm"), // true
      !"barfoo.htm".endsWith("foo.htm"), // false (here you go)
         !"foo.htm".endsWith("foo.htm"), // false (here you go)
       !"test.html".endsWith("foo.htm"), // true
        !"test.htm".endsWith("foo.htm")  // true
    
    );

    0 讨论(0)
提交回复
热议问题