String function questions

I still don’t have a firm grasp on how string functions work, as will be obvious from this attempt:

{RuinLabel==1 ? “H”+(CurrentZone.endsWith(1|4|7) ? “7” : CurrentZone.endsWith(2|5|8) ? “8” : “9”) : RuinLabel==2 ? “H”+(CurrentZone.endsWith(1|4|7) ? “4” : CurrentZone.endsWith(2|5|8) ? “5” : “6”) : RuinLabel==3 ? “H”+(CurrentZone.endsWith(1|4|7) ? “1” : CurrentZone.endsWith(2|5|8) ? “2” : “3”) : RuinLabel==4 ? “P”+(CurrentZone.endsWith(1|4|7) ? “7” : CurrentZone.endsWith(2|5|8) ? “8” : “9”) : RuinLabel==5 ? “P”+(CurrentZone.endsWith(1|4|7) ? “4” : CurrentZone.endsWith(2|5|8) ? “5” : “6”) : “P”+(CurrentZone.endsWith(1|4|7) ? “1” : CurrentZone.endsWith(2|5|8) ? “2” : “3”)}

What I want is for Two things to be checked, RuinLabel, and CurrentZone. If RuinLabel is 1, and CurrentZone ends with a 1, 4, or 7, I want the piece to be sent to H7, etc.

If someone can tell me what I’ve done wrong, I’d be most grateful.

The endswith() method only takes a basic string, not a regular expression. You need to use the matches() string method instead: CurrentZone.matches(".*[147]") should give you the result the want (.* matches any number of any characters at the start of the string, while [147] matches a 1, 4, or 7 at the end.)

Thanks!