I need to add markup to some text using JavaScript regular expressions. In Python I could do this with:
>>> import re
>>> re.sub('(banana|apple)', r'<b>\1</b>', 'I have 1 banana and 2 apples!')
'I have 1 <b>banana</b> and 2 <b>apple</b>s!'
What is the equivalent in JavaScript? string.replace(regex, newstring) seems to only take a raw string for replacing.