Say I have a url like /dir/name.json and I want to select and return anything which is between /dir/ and .json, in this case name. So I came up with something like this:
> var url = "/dir/name.json";
> var pattern = /\/\w+\./
> url.match(pattern)
[ '/name.', index: 4, input: '/dir/name.json' ]
but I just want to match name and not /name.
Of course there is another way to do this by using substr:
> var url = "/dir/name.json";
> url.substr(5, url.length-10)
'name'
but I wonder if I can do this using Regex
url.match( /dir\/(.*?)\./ )[1]/\/dir\/(\w+)\.json/and name will be in the first captured group