Putting a space within a range quantifier in a regex seems syntactically valid:
/.{1, 2}/ # => /.{1, 2}/
However, such space seems to alter the behaviour compared to when there is no such space:
"a" =~ /.{1,2}/ # => 0
"a" =~ /.{1, 2}/ # => nil
What would be the meaning of a regex with space within a range like /.{1, 2}/?
/.{1, 2}/
matches "a{1, 2}". Though it is syntactically valid, the {1, 2} stops being a limiting quantifier.
Once a space appears between the comma and the max numeric value, {1, 2} behaves as a literal string match.
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