I have a question about the way .replace() works
I know that we can use subpatterns within the replace text like this
var somestr="foobar";
var newstr = somestr.replace(/foo([a-zA-Z]*)/g,"bar$1")
alert(newstr) //"barbar"
However, I am wondering if it is even possible to use the subpattern in an object property, like this.
var somestr = "foobar";
var someobj = {bar:'fuu',two:'uuf'}
var newstr = somestr.replace(/foo([a-zA-Z]*)/g, someobj["$1"])
alert(newstr) //"fuu" ?
My expected result would have been to get the 'bar' property of someobj, which would be "fuu", however the actual result is undefined, which would lead me to believe this is impossible.
How could I otherwise accomplish similar functionality? Perhaps one of you JS gurus could shed some light on this.
The real-world purpose behind this is I have a template system that uses shorttags to display pieces of data from a requested JSON object, who's code I am attempting to streamline.