I have a weird situation. I am using a Regex testing some strings. I would like to seal them to a class, like the following:
export class RegexPattern {
static price = (/^\d*(\.\d{1,2})?$/g);
static phone = (/^([0-9]{0,5}-)?[0-9]{10}$/g);
}
So lets say the input is '32'
But when I use it to test same strings twice, the first time will pass, the second time will fail, eg:
RegexPattern.price.test('32') //return ture
RegexPattern.price.test('32') // return false
But if I use it with bare Regex, without sealing:
(/^\d*(\.\d{1,2})?$/g).test('32') //return ture
(/^\d*(\.\d{1,2})?$/g).test('32') // return true
My question is why did this happen?