I need a RegExp to test strings that should consist of the valid whole decimal numbers including zero (0
, 1
, 12
, 123
, but not 00
or 0123
) mixed with a special character (such as x
) in free occurrences:
0
, 1
, 123
, x
, xx
, x0
, 0x
, x0x
, 0x0
, xx123x0
, x1000xx5xxx
, …
I came up with the following:
new RegExp('^0?$|^((?!0)[0-9]+|x0$|0x|x+)+$')
Unfortunately, it do not work 100%, e.g. a valid string is not accepted: 0x0
.
Thanks for any help!