Regex that matches anything not ending in .json

前端 未结 4 1064
天命终不由人
天命终不由人 2020-12-21 01:03

For a web app I\'m trying to come up with a javascript regex that matches anything not ending in .json. Sounds simple but I\'m finding it pretty damn hard.

4条回答
  •  梦毁少年i
    2020-12-21 01:23

    Try /^(?!.*\.json$).*$/

    /^(?!.*\.json$).*$/.test("foo.json")
    false
    /^(?!.*\.json$).*$/.test("foo")
    true
    /^(?!.*\.json$).*$/.test("foo.html")
    true
    

提交回复
热议问题