skip to Main Content

I am frequently in a situation where, after finishing work on multiple open photoshop documents, I want to play a specific action on a few of them. The document names ALWAYS match a pattern that should be pretty easy to match with regex. Essentially:

 -If the document name is 5 or 6 digits + "F", play action A.
 -If the document name is 5 or 6 digits + "FX", play action B.
 -If the document name is 5 or 6 digits + "B", play action A.
 -If the document name is 5 or 6 digits + "BX", play action B.

I gather that getByName only works with exact string matches, so in order to use regex I will need a for loop to look through every open doc, check for a regex .match, then play the correct action. But I am having trouble achieving the desired result.

p.s. the targeted documents have never been saved and therefor have no extensions, so the regex pattern DOES NOT need to account for this.

Thanks!

2

Answers


  1. I take it your after the regex?
    Try

    (d{5,6}F$|d{5,6}B$) // for action A
    (d{5,6}FX$|d{5,6}BX$) // For action B
    
    Login or Signup to reply.
  2. It seems like RegExp in JavaScript for photoshop didn’t implemented the d. So I successfully used [0-9] instead.

    var reg1 = new RegExp ('([0-9]{5,6}F$|([0-9]{5,6}B$');
    var reg2 = new RegExp ('([0-9]{5,6}FX$|([0-9]{5,6}BX$');
    

    In case of a match the result will be two times the file name as an array. A mismatch will be null.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search