The best way to do this would be to iterate through each element and iterate through the class list of each element and check for "span", replacing the class if so. You can do that like so:
$('.row div').each(function () {
var $object = $(this);
$($(this).attr('class').split(' ')).each(function (i) {
// If you want particular span classes to become new classes
if(this.toString().indexOf("span3") >= 0) {
$object.removeClass(this.toString());
$object.addClass('special'); // New class to be added
}
// If you want all classes with "span" in them to become a new class
else if (this.toString().indexOf("span") >= 0) {
$object.removeClass(this.toString());
$object.addClass('span1'); // New class to be added
}
});
});
Demo here. This also includes an alternative method that strips the end of each class to get the same result