What about:
£((\d|[1-9]\d|1[0-4]\d|15[0-4])(\.\d{2})?|155(\.00)?)
The regex works as follows: it always starts with the leading pound sign (£
). Next it considers two cases: the one where the value is less than 155
and the one where it is 155
. The case of 155
is simple: 155(\.00)?
: 155
optionally followed by a dot and two zeros.
The case of less than 155
is more complex: we branch into several cases:
- the one with one digit
\d
(zero to nine);
- the one with two digits, but no leading zeros:
[1-9]\d
;
- the one with three digits: but since the result should be less than
155
we again have to branch:
- the ones less than
150
: these start with a 1
followed by a number between 0
and 4
(inclusive) followed by any digit \d
, so 1[0-4]\d
;
- the ones greater than or equal to
150
, but less than 155
, these all start with 15
and are followed by something in the range of 0
to 4
(inclusive), so 15[0-4]
.
All these are followed optionally by a dot and two digits (\.\d{2}
).
This regex reject numbers with leading zeros (like 09.12
) except of course if there is one digit: 0.85
is allowed.
I here assumed there are always two digits after the decimal dot(so 0.1
and 14.135
are not allowed), in case an arbitrary amount is allowed, simply replace \.\d{2}
with \.\d+
(in case at least one digit is required), or \.\d*
if even no digits are allowed.