I need to write regex to match that first characters is "Am" or "x" and other is only digits (5 times). Here is my regex:
"[Am|x]\\d{5}".toRegex()
Full:
"Am11111".matches("[Am|x]\\d{5}".toRegex())
However, this regular expression does not work correctly. It defines matches separately on A, m and x. But I need Am and x.
For example:
Am11111 – this is must be correct
x11111 – this is must be correct
a11111 – this is incorrect
m11111 – this is incorrect too
Please, help me.
>Solution :
You almost got it, just use () instead of []
(Am|x)\\d{5}