jQuery - regexp selecting and removeClass()?

jquery, regex

Solution

If only numbers are acceptable, but there can be other characters too, I would start with something like this (not tested, but edited with help from comments):

$("[class^='table-col-']").removeClass( function() { /* Matches even table-col-row */
     var toReturn = '',
         classes = this.className.split(' ');
     for(var i = 0; i < classes.length; i++ ) {
         if( /table-col-\d{1,3}/.test( classes[i] ) ) { /* Filters */
             toReturn += classes[i] +' ';
         }
     }
     return toReturn ; /* Returns all classes to be removed */
});

Problem

I've been given several auto-generated HTML docs that are thousands of lines long, and I need to clean up the source. Mostly need to remove classnames like "table-col-##". This is a two-step problem: - Select any and all classes that have table-col-##, where ## is an integer between 0-999 - Remove the matching class from the element, without removing any of the other classes So it boils down to: I need a way, if possible, to use regexps in $() selectors, and then either to obtain the selected class in each() - or apply the regexp to $.removeClass(). Can anyone point me in the right direction? UPDATE: Is there any sort of $.removeClass([selected]) functionality? That seems like the easiest way to solve the second part.

Original source