I imagine the perforce would be terrible, but does jquery have a plugin that does: $(sel).match(regex, function(match){ // code });