In a certain element, I need to select different strings that match a certain regex and wrap them with tags. How can I do that ?
I tried :
var str = jQuery("#my_div").html();
var regex = "\([a-z]{2}\)";
jQuery("#my_div").html(str.replace(regex, "<span>$1</span>"));
.. but this wraps the whole element instead of the selected string in the element.
The problem with your example is you have no capturing group, change your regex to
(\([a-z]{2}\))Here is an example of a working regex replace in html: http://jsfiddle.net/gibble/NYVWg/