Is it possible that an array of string replacements using regex can use eval to execute and return a value from a function which I need to be done via this method:
var message = $('#message').html();
var searchstring = [
/<span style="color: rgb((.*), (.*), (.*));">(.*)<\/span>/gi,
// other regex
];
var replacestring = [
eval('RGBtoHex($1, $2, $3)'),
// other regex
];
for(i = 0; i < searchstring.length; i++)
{
message = message.replace(searchstring[i], replacestring[i]);
}
$('.message-box').val(message);
I'm trying to convert RGB to a hexadecimal value so it should change to something like: rgb(255, 255, 255) to #FFFFFF. However, when I do this it says in Firebug: $1 is not defined which is located for this: eval('RGBtoHex($1, $2, $3)'),.
How will I be able to execute an eval() function to return rgb to a hexadecimal value while doing string replacements with .replace()?
Everything works perfectly except the eval part.