Regular expression: matching only if not ending in particular sequence

前端 未结 2 1364
悲哀的现实
悲哀的现实 2021-01-01 18:41

I would like to test a url that does NOT end in .html

This is the pattern I come up with:

[/\\w\\.-]+[^\\.html$]

T

2条回答
  •  庸人自扰
    2021-01-01 19:10

    You can use a negative lookbehind assertion if your regular expression engine supports it:

    ^[/\w\.-]+(?

    If you don't have lookbehind assertions but you do have lookaheads then you can use that instead:

    ^(?!.*\.html$)[/\w\.-]+$
    

    See it working online: rubular

提交回复
热议问题