Regex for matching a pattern with one length or another -


I must match strictly with a pattern of 10-character lengths or 12 (not 11). Then this will not work.

  [0- 9] {10,12}  

I

  ([ 0-9] {10} | [0- 9] {12})  

?

You can optionally set four or group to ? can be used:

  \ d {10} (\ d \ d)?  

Do not forget to match the beginning and end if the whole ridge is x:

  ^ \ d {10} (\ d \ d)? $  

Comments