0

I'm trying to match a pattern in powershell, any 3 letters followed by any 2 numbers, example: abc00

Trying:

'abc00' -match '[a-zA-Z]{3}[0-9]{2}'

returns TRUE

but :

'abcdefg0000' -match '[a-zA-Z]{3}[_0-9]{2}'

also returns TRUE.

How do I limit it so if the string doesn't contain exactly 3 letters and 3 numbers, it returns false?

Thank you!

Rakha
  • 1,874
  • 3
  • 26
  • 60
  • 1
    Surround it with `^$` or `\b`: `^[a-zA-Z]{3}\d{2}$` or `\b[a-zA-Z]{3}\d{2}\b`. Also, don't post the same question multiple times. At least you deleted your old question, but try to only post it once. – ctwheels Jan 08 '18 at 15:08
  • https://stackoverflow.com/questions/3994493/checking-whole-string-with-a-regex – Veltzer Doron Jan 08 '18 at 15:09
  • also, whats the deal with the underscore ('_')? – Veltzer Doron Jan 08 '18 at 15:10
  • ctwheels, thanks. I deleted my previous questions as i felt it was unclear but i should've edited it. Thank you. – Rakha Jan 08 '18 at 15:58

0 Answers0