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

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -