@Michael: Thank you for the awesome code!
Annotation: line 4 must be the following:
var re = /rA/;// a reg exp var matches = collectNamesAM(re);// get array of matching layer indexes for( var l = 0; l < matches.length; l++ ){ makeActiveByIndex( matches[l], false ); // do something with layer alert(app.activeDocument.activeLayer.name); }// next match if any