Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

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

Explorer ,
Jul 14, 2017 Jul 14, 2017

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();

TOPICS
Actions and scripting
842
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines

correct answers 1 Correct answer

Community Expert , Jul 15, 2017 Jul 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

Translate
Adobe
Enthusiast ,
Jul 15, 2017 Jul 15, 2017

try this:

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Community Expert ,
Jul 15, 2017 Jul 15, 2017
LATEST

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

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines