Figure I'll put this here for posterity.
What is the regex for ####.@@@@X?
- Where "#" is any number up to 4 digits before the decimal point but only one leading 0 allowed
- Where "@" is any number up to 4 digits after the decimal point
- Where "X" is a single alpha character in a given list (
A or a,X or x) that must come last
Examples to pass:
- .309x
- 0.309
- 1
- 0.0
- 1.0234
- 0.2345X (IMPORTANT, should only allow one leading 0)
- 1.23A
- 7300.3211x
- 0.1a
Examples to fail:
- 01.123
- 00.234
- a.123
- 1.23p
- 00.43x
What I have now:
^\d{1,4}(\.\d{0,4})?$- This works for 4 numbers before and after decimal
- But doesn't account for the the single leading 0 NOR the alpha at the end.
EDIT 1:
- Testing your solutions made me realize some other cases.
- I updated the pass/fail scenarios
- The biggest revelations are:
- The leading number is optional
- The decimal point is optional
- The alpha character at the end is optional
- A leading 0 should only be followed the decimal point.
- e.g: 0.123 yes; 01.234 no
Answers:
- @TheFourthBird and @AaronMorefield got it with these:
^(?!00|0[1-9]\.)(?:\d{0,4}\.\d{1,4}[aAxX]?|\d{1,4})$
((^[1-9])(\d{0,3})|^0|^)((\.?)\d{0,4})(|[A-Za-z])$
I'll be studying these!