ruby - Why does this regular expression for ranges fail? -
the intention create regular expression parses inclusive (..
) , exclusive (...
) ranges given string.
my edge cases following:
- the
initial
,final
values of range can't contain spaces. - only inclusive (
..
) , exclusive (...
) ranges accepted. - the
final
value can't contain dots (.
) @ beginning. - the whole string should valid range.
that said, string invalid representation of range be:
"1 2..20"
,"1 2...20"
,"12..2 0"
"1....10"
or"
1.10`
this regular expression got far
/\a([^.\s]+)(\.{2,3})([^.][^\s]+)\z/
however fails. seems cause [^.]
part in third capture group. works without [^.]
, unfortunately not cover cases.
i'm using ruby 2.2.1.
try
/\a([^\s]*[^.])(\.{2,3})([^.][^\s]*)\z/
this uses *
in place of +
, third capture group allowed capture 1 character (your previous expression required capture @ least 2 characters).
Comments
Post a Comment