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

Criteria for testing numbers and spaces while using indexOf

Community Beginner ,
Nov 06, 2024 Nov 06, 2024

Copy link to clipboard

Copied

// var name = layer.name;

// gets changed over to null given certain criteria

// var name = '';

 

// criteria depends on layer name starting with “XX T”

// and have numbers 1 thru 99 following ... as in “XX T##”

// and after the numbers also test that if there are more characters in the layer name that a space follows ... as in “XX T1 “ or “XX T99 “ so that "XX T1 Teststing 123" can be true

 

// results are that layer names that do not match the criterial have var name = ‘’;

// and layers that do start with "XX T##" or “XX T## ” have the “var name = “ left unchanged

 

// examples of layers with (var name = layer.name;) where the variable is left unchanged:

// “XX T1” or “XX T75” or “XX T1 “ or “XX T99 “ or “XX T1 testing 123”

// for the example "XX T1" to be true there would be no reason to test that a space follows the last number but the layer name must not cotain anything else and be the exact name match "XX T1"

// if there is text following the last number a blank space must be included in criteria as in “XX T1 testing 123”

 

// examples of layers that have the variable name (var name = layer.name;) changed to (var name = ‘’;)

// layer names that do not start with "XX T"

// “XX T” with no two possible numbers following the “T”

// “XX T 75” with a blank space after the “T”

// “XXT1” with no blank space between “X T”

// “123XX T1” that don’t start with “XX T”

// “XX T1Testing 123” that don’t have a space following the last number

 

 

 

if (isPossible) {

                var name = layer.name;

                if (name.indexOf(‘XX T') === -1) name = '';        // need help expanding this criteria

            }

 

 

// based on criteria I push the contents of the variable “name” to an array

 

 

// then in array

            if (layer.name === ""){

                var name = "";

            }

 

 

// array condition if layer name starts with “XX T##“ or “XX T## “

                if (layer.name !== ""){

                    var name =  layer.name

            }

 

 

// actions that follow but the way I have it set up only works  for exact name match only

// I need help including instances where charaters follow as in “XX T1 testing 123”

// also not sure if (!!name) is required

 

        if (name === “XX T1" && (!!name)) {.

            var t1 = “Cool Beans”;

        }

 

       if (name === “XX T69” && (!!name)) {

            var t69 = “Yeah Buddy”;

        }

TOPICS
How-to , Scripting

Views

272

Translate

Translate

Report

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 2 Correct answers

Participant , Nov 06, 2024 Nov 06, 2024

Not really sure what youre asking in your post, but it seems like you need to use some grep searching to test if a layer name is accurate

var layerName = layer.name
if(layerName.toString().search(/XX T\d+( .+)?/gi)!=-1){
 /*the search will return 0 if the layername satisfies the search of having XX T any number of digits and maybe extra text after it. if it doesnt meet that criteria it will return -1 for the search*/
}

Votes

Translate

Translate
Advocate , Nov 06, 2024 Nov 06, 2024

Careful!

Do not use name as a non-varaible

( name == "Adobe Illustrator")

name.indexOf("XXT",0) return -1

Votes

Translate

Translate
Adobe
Participant ,
Nov 06, 2024 Nov 06, 2024

Copy link to clipboard

Copied

Not really sure what youre asking in your post, but it seems like you need to use some grep searching to test if a layer name is accurate

var layerName = layer.name
if(layerName.toString().search(/XX T\d+( .+)?/gi)!=-1){
 /*the search will return 0 if the layername satisfies the search of having XX T any number of digits and maybe extra text after it. if it doesnt meet that criteria it will return -1 for the search*/
}

Votes

Translate

Translate

Report

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 Beginner ,
Nov 06, 2024 Nov 06, 2024

Copy link to clipboard

Copied

Thanks for the help ... and most importantly I will now learn about search patterns using grep.

Votes

Translate

Translate

Report

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 Beginner ,
Nov 06, 2024 Nov 06, 2024

Copy link to clipboard

Copied

I thought I would be able to get this on my own ... how about a grep for the exact match of "XX T1" thru "XX T99" where it would fail past 99 or if the string contains any other character after the last number. My best attempt so far:

if(layerName.toString().search(/XX T\^(0?[1-9]|[1-9][0-9])$?/gi)!=-1)

 

Votes

Translate

Translate

Report

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 Beginner ,
Nov 07, 2024 Nov 07, 2024

Copy link to clipboard

Copied

Got it to work for resolving "XX T" with any number after that and nothing else after. I also removed the -i option so it is case sensitive. 

 

 

if(layerName.toString().search(/XX T\d+$/g)!=-1)

 

Votes

Translate

Translate

Report

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 Beginner ,
Nov 07, 2024 Nov 07, 2024

Copy link to clipboard

Copied

if(layerName.toString().search(/^XX T\d+$/g)!=-1)

Small but critical tweak ... I added the "^" before "XX T" to make sure nothing preceeds it.

Votes

Translate

Translate

Report

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
Advocate ,
Nov 06, 2024 Nov 06, 2024

Copy link to clipboard

Copied

Careful!

Do not use name as a non-varaible

( name == "Adobe Illustrator")

name.indexOf("XXT",0) return -1

Votes

Translate

Translate

Report

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 Beginner ,
Nov 08, 2024 Nov 08, 2024

Copy link to clipboard

Copied

LATEST

I spent some time learning about the regex search pattern options once RobOctopus pointed me in the right direction. At some point I tried the 1,2 but I had it as [1,2] and never got it to resolve. The best I came up with was (/^XX T\d+$/g) but now with your help I can see I can use the ( /$) to include the space at the end ... and much more importantly limit the pattern to only two digits. Much appreciated.

Votes

Translate

Translate

Report

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