I've a regex that will only match one character of the strings. I want to test the lentgh of its containing string and if it was greater than 4 then make the replacement. For example, the regex is /\d/. I want to use the functional form of replace to match 12345 but not 1234.
Something like:
text.replace(regex, function(match) {
if (STRING.length > 4)
return replacement
else
return match;
});
Note:
/\d/ is just an example. I didn't mention the real regex to focus on my real question, illustrated above.