Search code examples
adobe-illustrator

Illustrator - Select layer by explicit name only


This script selects every layer that contains the word "shadow" but it also picks up any layer that has that word.

How do I explicitly only select "shadow" and "shadow-7" for example so it ignores "shadow-4", "shadow-5" etc?

var aDoc = app.activeDocument;
var pI = aDoc.pageItems;
aDoc.selection = null;
for (i=pI.length-1; i>=0; i--) {
    if (pI[i].name.match(/shadow/i) != null) {
        pI[i].selected = true;
        }
    }

Solution

  • You need to change your regex /shadow/i to /^shadow$/i