RegEx/Unix/Cron_Interval.regex.txt

# Matches a Cron interval
(?<Minute>(?>
  (?<Any>\*) # An asterisk
    | # or
  (?<Start>
    (?>[0-5][0-9]|[0-4]\d|\d{1,1}) # A number between 0 and 59
  )
  (?<End>
    \- # a dash
    (?>[0-5][0-9]|[0-4]\d|\d{1,1}) # followed by another number between 0 and 59
  ){0,1}
  (?<Or>\,){0,1} # followed by an optional comma (which indicates 'or')
)){1,}\s # A space
(?<Hour>(?>
  (?<Any>\*) # An asterisk
    | # or
  (?<Start>
    (?>[0-2][0-3]|[0-1]\d|\d{1,1}) # A number between 0 and 23
  )
  (?<End>
    \- # a dash
    (?>[0-2][0-3]|[0-1]\d|\d{1,1}) # followed by another number between 0 and 23
  ){0,1}
  (?<Or>\,){0,1} # followed by an optional comma (which indicates 'or')
)){1,}\s # A space
(?<Day>(?>
  (?<Any>\*) # An asterisk
    | # or
  (?<Start>
    (?>3[0-1]|[0-2][1-9]|[1-9]) # A number between 1 and 31
  )
  (?<End>
    \- # a dash
    (?>3[0-1]|[0-2][1-9]|[1-9]) # followed by another number between 1 and 31
  ){0,1}
  (?<Or>\,){0,1} # followed by an optional comma (which indicates 'or')
)){1,}\s # A space
(?<Month>(?>
  (?<Any>\*) # An asterisk
    | # or
  (?<Start>
    (?>1[0-2]|[1-9]) # A number between 1 and 12
  )
  (?<End>
    \- # a dash
    (?>1[0-2]|[1-9]) # followed by another number between 1 and 12
  ){0,1}
  (?<Or>\,){0,1} # followed by an optional comma (which indicates 'or')
)){1,}\s # A space
(?<DayOfWeek>(?>
  (?<Any>\*) # An asterisk
    | # or
  (?<Start>
    (?>[0-6]) # A number between 0 and 6
  )
  (?<End>
    \- # a dash
    (?>[0-6]) # followed by another number between 0 and 6
  ){0,1}
  (?<Or>\,){0,1} # followed by an optional comma (which indicates 'or')
)){1,}