ruby - Why does this regular expression for ranges fail? -


the intention create regular expression parses inclusive (..) , exclusive (...) ranges given string.

my edge cases following:

  1. the initial , final values of range can't contain spaces.
  2. only inclusive (..) , exclusive (...) ranges accepted.
  3. the final value can't contain dots (.) @ beginning.
  4. 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

Popular posts from this blog

twig - Using Twigbridge in a Laravel 5.1 Package -

firemonkey - How do I make a beep sound in Android using Delphi and the API? -

jdbc - Not able to establish database connection in eclipse -