Skip to main content
heyvirgil
Known Participant
July 14, 2017
Answered

How do I implement a regex to match a group name in this script?

  • July 14, 2017
  • 2 replies
  • 898 views

Basically I want to be able to select the group names "Notes" (always layer 0).

I have achieved that when the layer group is named exactly with capital case, but i'd like it to be case insensitive, this is the regex to match that in javascript:

searchText.match(/(??<notes>notes)/im)

Here is my script currently:

main();

function main() {

  if (!documents.length) return;

  var doc = app.activeDocument;

  var notesLayer = doc.layers[0];

  // Validate that layer 0 is the "Notes" layer

  if(notesLayer.name !== "Notes"){

        alert("The Notes layer does not exist.")

        return;

    }

   

  notesLayer.visible = true;

  //var doc_path = doc.path;

  //var Name = app.activeDocument.name.replace(/\.[^\.]+$/, '');

  //var saveFile = File(doc.path + "/_jpg/" + Name + "-notes.jpg");

  //SaveForWeb(saveFile, 80); //change quality here

}

var doc = app.activeDocument; 

//var Path = doc.path; 

var Name = doc.name.replace(/\.[^\.]+$/, '');  

var saveFile = File(doc.path + "/_jpg/" + Name + "-notes.jpg");

//var Suffix = "-specs"; 

//var saveFile = File(Path + "/_jpg" + Name + Suffix + ".jpg"); 

SaveJPEG(saveFile, 6); 

 

function SaveJPEG(saveFile, jpegQuality){ 

jpgSaveOptions = new JPEGSaveOptions(); 

jpgSaveOptions.embedColorProfile = false; 

jpgSaveOptions.formatOptions = FormatOptions.STANDARDBASELINE; 

jpgSaveOptions.matte = MatteType.NONE; 

jpgSaveOptions.quality = jpegQuality; 

activeDocument.saveAs(saveFile, jpgSaveOptions, true,Extension.LOWERCASE); 

}

//function SaveForWeb(saveFile, jpegQuality) {

// var sfwOptions = new ExportOptionsSaveForWeb();

// sfwOptions.format = SaveDocumentType.JPEG;

// sfwOptions.includeProfile = false;

// sfwOptions.interlaced = 0;

// sfwOptions.optimized = true;

// sfwOptions.quality = jpegQuality; //0-100  

// activeDocument.exportDocument(saveFile, ExportType.SAVEFORWEB, sfwOptions);

function revert() {

  var idRvrt = charIDToTypeID( "Rvrt" );

  executeAction( idRvrt, undefined, DialogModes.NO );

}

revert();

This topic has been closed for replies.
Correct answer pixxxelschubser

Hi heyvirgil

There are more than one Regex for this.

One way could be

main ();

function main() {

  if (!documents.length) return;

  var doc = app.activeDocument;

  var notesLayer = doc.layers[0];

  // Validate that layer 0 is the "Notes" layer

  if(notesLayer.name.match(/notes/i) == null) {

        alert("The Notes layer does not exist.");

        return;

    }

alert ("found: " + notesLayer.name.match(/notes/i) + " layer");

// your own stuff

}

Have fun

2 replies

pixxxelschubser
Community Expert
pixxxelschubserCommunity ExpertCorrect answer
Community Expert
July 15, 2017

Hi heyvirgil

There are more than one Regex for this.

One way could be

main ();

function main() {

  if (!documents.length) return;

  var doc = app.activeDocument;

  var notesLayer = doc.layers[0];

  // Validate that layer 0 is the "Notes" layer

  if(notesLayer.name.match(/notes/i) == null) {

        alert("The Notes layer does not exist.");

        return;

    }

alert ("found: " + notesLayer.name.match(/notes/i) + " layer");

// your own stuff

}

Have fun

Jarda Bereza
Inspiring
July 15, 2017

try this:

if (notesLayer.name.toLowerCase() !== "notes")