So I'm writing a script in powershell (not the point) where I'd like to match a specific string format, but the string can be longer then my format and I dont want that to be a match. I want it to be a certain length only.
For example. I want my format to match [A-Z]{3}[TLZ]\d{5} but only that. So for example, STSZ43332 is a match, but I dont want to match STSZ433321. I know I could run a if statement before to check the length but was wondering if its possible inside the regex.
If it matters, this is my If statement in powershell.
If ($Name -match "[A-Z]{3}[TLZ]\d{5}") {Write-Host "Found match"}
The problem is that if $name is longer then my expected 9 characters (from the regex} it could still come back as true if the regex string can be found inside $name. As I said, I could do if $name.length to match that $name is only 9 but wanted to know if regex has a way of doing that too.
thanks