I use ruby-like wrapper around nim's `re`, compared to the `scanf` code from 
the article
    
    
    var min1, max1, min2, max2: int
    var field: string
    
    for line in input.split("\n"):
      if line.scanf("$+: $i-$i or $i-$i", field, min1, max1, min2, max2):
        echo [min1..max1, min2..max2]
    
    
    Run

With ruby-like wrapper it looks like:
    
    
    for line in input.split("\n"):
      let found = re".+: (\d+)-(\d+) or (\d+)-(\d+)".parse4(line)
      if found.is_some:
        let (min1, min2, min3, min4) = found.get
        echo [min1..max1, min2..max2]
    
    
    Run

Reply via email to