Skip to main content
Known Participant
Nov 6, 2024 3:22 PM UTC
Answered

Criteria for testing numbers and spaces while using indexOf

// 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”;

        }

This topic is closed to new replies. Start a new post to keep the conversation going.
renél80416020
renél80416020Correct answer
Inspiring
Nov 6, 2024 6:49 PM UTC

Careful!

Do not use name as a non-varaible

( name == "Adobe Illustrator")

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

7 replies

nutradialAuthor
Known Participant
Nov 9, 2024 6:09 AM UTC

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.

Translate
renél80416020
renél80416020Correct answer
Inspiring
Nov 6, 2024 6:49 PM UTC

Careful!

Do not use name as a non-varaible

( name == "Adobe Illustrator")

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

Translate
RobOctopus
Inspiring
Nov 6, 2024 3:31 PM UTC

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*/
}
Translate
nutradialAuthor
Known Participant
Nov 7, 2024 2:31 AM UTC

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

Translate