Reputation: 30102
I want to do something like this:
"3*4".replace(/([0-9]+)[*]([0-9]+)/g, String(Number("$1") * Number("$2")))
And no, i don't want to do that, but something more complex.
Upvotes: 0
Views: 467
Reputation: 34395
This can also be done in straight JavaScript like so:
function process(text) {
return text.replace(/(\d+)\*(\d+)/g, function(m0, m1, m2) {
return m1.valueOf() * m2.valueOf();
});
}
Upvotes: 0
Reputation: 40543
"3*4".replace(/(\d+)\*(\d+)/g, function():String {
return String(Number(arguments[1]) * Number(arguments[2]));
});
Upvotes: 5