First of all, pardon my hacky code, I'm just trying to try this out and I'm learning javascript for the first time. Basically, Given the string "abc!random{3}" would mean return a string that starts with "abc" and ends with a random number from 0-3.
Here is what I have:
var pattern=/!random{([^{]*?)}/gi;
var text="abc!random{3}def!random{4}ghi!random{!random{3}}";
while (pattern.test(text))
{
text=text.replace(pattern, Math.random() * parseInt("$1"));
}
The problem is the parseInt function. It seems like the $1 does not get passed to it..the value of it gets cleared or something. If I do:
text=text.replace(pattern, "$1");
It correctly returns what is in between the { }, so the regex is working and the match is being stored in $1. However, as soon as I use it as a parameter to $1, it seems like the value of it is cleared. What gives?