Mabe this can help get you started.
It collects two Arrays, one of all the Layers with a name like »group x« and one of the layers with a name like »set x«.
You can then run them against each other to compare the names and process them accordingly.
// 2024, use it at your own risk;
if (app.documents.length > 0) {
var theGroups = collectLayersOfName (/^group \d{1,3}$/i);
var theSets = collectLayersOfName (/^set \d{1,3}$/i);
alert ("layers with »group« in their names\n"+theGroups.join("\n"));
alert ("layers with »set« in their names\n"+theSets.join("\n"));
};
////// collect layers //////
function collectLayersOfName (theRegExp) {
// get number of layers;
var ref = new ActionReference();
ref.putProperty(stringIDToTypeID('property'), stringIDToTypeID('numberOfLayers'));
ref.putEnumerated( charIDToTypeID("Dcmn"), charIDToTypeID("Ordn"), charIDToTypeID("Trgt") );
var applicationDesc = executeActionGet(ref);
var theNumber = applicationDesc.getInteger(stringIDToTypeID("numberOfLayers"));
// process the layers;
var theLayers = new Array;
for (var m = 0; m <= theNumber; m++) {
try {
var ref = new ActionReference();
ref.putIndex( charIDToTypeID( "Lyr " ), m);
var layerDesc = executeActionGet(ref);
var layerSet = typeIDToStringID(layerDesc.getEnumerationValue(stringIDToTypeID("layerSection")));
var isBackground = layerDesc.getBoolean(stringIDToTypeID("background"));
// if group collect values;
if (layerSet != "layerSectionEnd" /*&& layerSet != "layerSectionStart" && isBackground != true*/) {
var theName = layerDesc.getString(stringIDToTypeID('name'));
var theID = layerDesc.getInteger(stringIDToTypeID('layerID'));
var theIndex = layerDesc.getInteger(stringIDToTypeID('itemIndex'));
var theColor = typeIDToStringID(layerDesc.getEnumerationValue(stringIDToTypeID("color")));
if (theName.match(theRegExp) != null) {theLayers.push([theName, theIndex, theID, theColor, theName.match(/\d{1,3}$/)])}
};
}
catch (e) {};
};
return theLayers
};