Jquery match

I have a big tree.
I want change all the ul css which id like ‘a + num + b + num’(num range from 1 - 99)

now it is hard to add a class to all the ul, so I tried use this code to match the id

But it caused some wrong Uncaught Error: HIERARCHY_REQUEST_ERR: DOM Exception 3 where is the problem? Thanks.

jQuery(document).ready(function(){
var divArray = $('.demo').children('ul');
var id = $('.demo').children('ul').attr('id');
for (mydiv in divArray) { 
if (id.match(/^a\\d{1,2}b\\d{1,2}$/)) { 
	$(mydiv).css({...}); 
	} 
} 	
});
<div class="demo">
<ul id="a1b77"></ul>
...
<ul id="a12b21"></ul>
<ul id="a12b22"></ul>
...
<ul id="a22b1"></ul>
...
<ul id="a22b101"></ul>/* not suit num range from 1 - 99, do not change the css style */
</div>

jQuery provides you with a way to easily extend it to do these sorts of things. I remember an example I saw some years back, although I wasn’t able to find it I’ve modified some code to suit:


$.extend($.expr[':'],{
    idMatch: function(elem,index,m) {
        var reg = new RegExp(m[3],"g");
        return reg.test($(elem).attr('id'));
    }
});

If you do something like that then you can pass through pretty much any regular expression to check on the ids:


var lists = $('ul:idMatch(^a[0-9]{1,2}b[0-9]{1,2}$)');

also maybe


$(function(){
    $(".demo").children("ul").each(
        function(){
            if($(this).attr("id").match(/^a\\d{1,2}b\\d{1,2}$/))
            {
                $(this).css(...);    
            }    
        
        }
    );
});