The code itself: (you can see it on DartPad)
void main() {
print(new RegExp("[0-9]|'|\"|\.").hasMatch('g')); // should return false
print(new RegExp("[0-9]|'|\"|\.").hasMatch('0')); // return correctly true
}
Output:
true
true
With the same version on regex101 but with JS, the return value is correct.
Is there something I'm missing with my RegExp or should I report a bug?
Either you use a raw string
print(new RegExp(r'''[0-9]|'|"|\.''').hasMatch('g'));
('''
is to avoid a conflict with "
inside the string)
or escape \
print(new RegExp("[0-9]|'|\"|\\.").hasMatch('g'));
DartPad example
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With