For a web application, I am trying to come up with a javascript regex that matches anything not ending in .json. It sounds easy, but I find it pretty damn complicated.
At first, I wanted to do it this way: ^.*(?!\.json$)but it clearly didn't work, as it just matches the whole line. Then I tried ^[^\.]*(?!\.json$), but matches abin abc.json.
I went so far as to come up with two regular expressions that do the job, but I want to have one regular expression that can do this.
^.*\.(?!json$)
^[^\.]*$
I like http://regex101.com/#javascript to check them out.
I am using regexp as part of ExpressJS's route definition app.get(REGEXP, routes.index).
source
share