Regex that matches anything not ending in .json

前端 未结 4 1063
天命终不由人
天命终不由人 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条回答
  •  自闭症患者
    2020-12-21 01:46

    You can always just get the file extension and then compare it.

    Regex to find file extension

    /\.[^.]*$/

    get the file extension with

    var extension = /\.[^.]*$/.exec("something.json");
    
    if(extension[0] === ".json"){
        //do something
    }
    

提交回复
热议问题