Say I have a line, for example:
var map = "/directory/:id/thumbnails/:size";
And I want to use this to match with another line (essentially the same thing that Rails uses to determine routes), for example:
var str = "/directory/10/thumbnails/large";
I would like to “compare” two strings and return a key-value pair or JSON object that represents the parts strthat are displayed in map, which in my example above looks like this:
obj = {
'id' : '10',
'size' : 'large'
}
Would this work well for JavaScript Regex? Can anybody help me?
source
share