Let's say I have this string:
<i id="1"></i><i id="2"></i><i id="3"></i>
and this object:
{
"1": "Red",
"2": "Green",
"3": "Blue"
}
Then I want to obtain this string:
<i color="Red"></i><i color="Green"></i><i color="Blue"></i>
Would be possible to make it through a regex replace?
I've tried this:
var stringIwant = stringIhave.replace(/id="(\d)"/g, 'color="' + myObject["$1"] + '"')
But it tries to read the property "$1" of the object, which doesn't exist. I also tried removing the quotes around $1:
var stringIwant = stringIhave.replace(/id="(\d)"/g, 'color="' + myObject[$1] + '"')
But I obtain a ReferenceError: $1 is not defined
I've tried more things, but nothing worth mentioning.
That's why I wonder if this is even possible. Any help?
<i>tag, though you can use it for your own purposes.