Adding a space
is going to invalid the second alternative
:
(^100([.]0{1,2})?)
because it says it must start with a space
character when it also specify a ^
.
The regex with the space
is equivalent to the regex without the second alternative:
^$|(^\d{1,2}([.]\d{1,2})?)$
Let's see the following snippet.
const reg1 = /^$| (^100([.]0{1,2})?)$|(^\d{1,2}([.]\d{1,2})?)$/;
const reg2 = /^$|(^100([.]0{1,2})?)$|(^\d{1,2}([.]\d{1,2})?)$/;
const str1 = '100';
const str2 = '90';
console.log(reg1.test(str1));
console.log(reg1.test(str2));
console.log('----------------------------');
console.log(reg2.test(str1));
console.log(reg2.test(str2));
const reg3 = /^$|(^\d{1,2}([.]\d{1,2})?)$/;
console.log('----------------------------');
console.log(reg3.test(str1));
console.log(reg3.test(str2));
For the help you can go to https://regex101.com
