-edit- NOTE the ?
at the end of .{2,}?
I found out you can write
.{2,}?
Isnt that exactly the same as bel
No, they are different. ^.{2,}?$
matches strings whose length is at least 2 (as seen on rubular.com):
12
123
1234
By contrast, ^.{2}$
only matches strings whose length is exactly 2 (as seen on rubular.com).
It's correct that being reluctant, .{2,}?
will first attempt to match only two characters. But for the overall pattern to match, it can take more. This is not the case with .{2}
, which can only match exactly 2 characters.