Question Testing number of digits with Regular Expressions

VBobCat

Well-known member
Joined
Sep 6, 2011
Messages
137
Location
S?o Paulo, Brazil
Programming Experience
3-5
I have to test a string that must match this pattern: any number of digits, a slash, and two or four digits, but not three (it is a year). So I'm using this boolean expression:

System.Text.RegularExpressions.Regex.IsMatch(texto, "^\d+/\d{2,4}$") And Not System.Text.RegularExpressions.Regex.IsMatch(texto, "^\d+/\d{3}$")


Here is my question: is there a way to test for two or four digits, but not three, in a single RegEx pattern?

Thank you very much!
 
Use the | (or) operator: (\d{2}|\d{4})
 
Back
Top