I'm trying to use a regular expression in C# to match a software version number that can contain:
- a 2 digit number
- a 1 or 2 digit number (not starting in 0)
- another 1 or 2 digit number (not starting in 0)
- a 1, 2, 3, 4 or 5 digit number (not starting in 0)
- an option letter at the end enclosed in square brackets.
Some examples:
10.1.23.26812 83.33.7.5 10.1.23.26812[d] 83.33.7.5[q]
Invalid examples:
10.1.23.26812[ 83.33.7.5] 10.1.23.26812[d 83.33.7.5q
I have tried the following:
string rex = @"[0-9][0-9][.][1-9]([0-9])?[.][1-9]([0-9])?[.][1-9]([0-9])?([0-9])?([0-9])?([0-9])?([[][a-zA-Z][]])?";
(note: if I try without the "@" and just escape the square brackets by doing "\[" I get an error saying "Unrecognised escape sequence")
I can get to the point where the version number is validating correctly, but it accepts anything that comes after (for example: "10.1.23.26812thisShouldBeWrong" is being matched as correct).
So my question is: is there a way of using a regular expression to match / check for square brackets in a string or would I need to convert it to a different character (eg: change [a] to a and match for *s instead)?