I’m trying to create a RegEx that matches the 3 patterns listed above. I can somewhat create a working RegEx for any of those 3 but my problem is creating one that works with all 4 of those. The allowed values are below, where D is any digit and the ‘.’ is never present as a trailing character (i.e. DDD. wouldn’t be valid). Also the V and E refer to those specific characters.
- ddd
- ddd.d
- ddd.dd
- Vdd
- Vdd.d
- Vdd.dd
- Eddd
- Eddd.d
Everything else should be invalid, such as:
- d
- dd
- V
- Vd
- Vdd. (trailing ‘.’)
- E
- Ed
- Edd
I’m not great with RegEx, but I could describe part of this pattern for the entries that start with V as the following:
V[0-9]{2,2}(\.[0-9]{1,2})?
I could write very similar statements for the all digit portion of entires and E prefix portion of entries. The problem is how to combine all 3 into a RegEx that doesn’t make my head spin to read. What’s a good RegEx to match all 3 patterns?
EDIT: I forgot to include the format Vdd.dd
EDIT: Some explanation: I just matched all 3 different formats:
says three digits optionally followed by a period matched with 1 or 2 digits.
says V followed by two digits with optional period and one or two digits
says three digits followed by an optional period with a single digit
Then I just surrounded each with () and combined them all with | (or).