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

Photoshop javascript Regular expression?

New Here ,
Oct 11, 2013 Oct 11, 2013

Hello,

I am looking to determine the name of a file by using a regular expression. I have three files each one has a different file name that I want to change to depending on the input. The three inputs have either _S_, _F_,_B_ in the name and then I want the reg exp to change the name dependant on this. I can get the _F_ and _B_ to work but the file with _S_ in changes to _F_

Javascript is very new to me. This is what i have done.

    var Packshot_S = new RegExp("_S_");
    var Planogram_F = new RegExp("_F_");
    var Planogram_B = new RegExp("_B_");
   
    // create another variable that tests the text string against the pattern. If nothing is found, the test will return "-1".
    var TypeTester = FileRefName.search (Packshot_S);
    if (TypeTester == -1) {
        alert("Packshot_S: " + Packshot_S + TypeTester);
        //Is a Packshot
        var View = "S";
        }
   
    var TypeTester = FileRefName.search (Planogram_F);
    if (TypeTester == -1) {
        alert("Planogram_F: " + Planogram_F + TypeTester);
        // Is a Planogram Front
        var View = "B";
        }  
   
    var TypeTester = FileRefName.search (Planogram_B);
    if (TypeTester == -1) {
        alert("Planogram_B: " + Planogram_B + TypeTester);
        // Is a Planogram Back
        var View = "F";
       

Thanks

Chris

TOPICS
Actions and scripting
1.6K
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
Adobe
Guru ,
Oct 11, 2013 Oct 11, 2013

At first glance it looks to me like you have var View reversed for "B" and "F".

I would combine the RegExp into one expression and convert the multiple if statements into a switch statement.

var re = new RegExp('_[SFB]_');

var typeTester = fileRefName.match(re);

typeTester==null ? "":typeTester = typeTester[0];

switch( typeTester ){

    case '_S_':

        alert("Packshot_S: "  + typeTester);

        var View = "S";

        break;

    case '_F_':

        alert("Planogram_F: "  + typeTester);

        var View = "F";

        break;

    case '_B_':

        alert("Planogram_B: " + typeTester);

         var View = "B";

         break;

}

Also the standard JavaScript naming convention is to start variables with a lowercase letter.

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
New Here ,
Oct 11, 2013 Oct 11, 2013
LATEST

Thank you Michael this has worked for me

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