duanhe1976 2017-04-19 08:14
浏览 72

陷入逻辑试图匹配模式?

I am running a script based on exetime and exetime is saved in database in the format of following.

* * * * * *
| | | | | | 
| | | | | +-- Year              (range: 1900-3000)
| | | | +---- Day of the Week   (range: 1-7, 1 standing for Monday)
| | | +------ Month of the Year (range: 1-12)
| | +-------- Day of the Month  (range: 1-31)
| +---------- Hour              (range: 0-23)
+------------ Minute            (range: 0-59)

Now I need to check exetime with current

M.H.DofM.MofY.DofW.Y

each field can have two possibilies , it could be respective field or it could be a "*" . what will be the best way two check this pattern with all combination with each field having 2 possibilities.

  • 写回答

1条回答 默认 最新

  • douyihuaimao733955 2017-04-19 08:24
    关注

    Here is the regexp I think :

    ([0-5]?[0-9]|\*)\.([0-1]?[0-9]|2[0-3]|\*)\.([1-2]?[0-9]|3[0-1]|\*)\.([0-9]|1[0-2]|\*)\.([1-7]|\*)\.(19[0-9][0-9]|2[0-9]{3}|3000|\*)
    

    Let's explain this one part by part, the | equals to the "and" of my explain; all the part are separate by \. which is the "."

    ([0-5]?[0-9]|\*) 
    

    Will match all number from 0 to 59 or * This ( as the others ) will allow you to use 00

    ([0-1]?[0-9]|2[0-3]|\*)
    

    Will match all number from 0 to 19 and from 20 to 23 or *

    ([1-2]?[0-9]|3[0-1]|\*)
    

    Will match all number from 0 to 29 and from 30 to 31 or *

    ([0-9]|1[0-2]|\*)
    

    Easy one; from 0 to 9 or from 10 to 12 or *

    ([1-7]|\*)
    

    Match 1 to 7 or *

    (19[0-9][0-9]|2[0-9]{3}|3000|\*)
    

    Match from 1900 to 1999 and from 2000 to 2999 and 3000 or *

    Here is an example : https://regex101.com/r/Orlp3o/2

    I let you test some more ;)

    Well, I edit my answer in order to add @Mark Baker one, https://github.com/mtdowling/cron-expression

    Now you can choose which one you want to use ;)

    评论

报告相同问题?

悬赏问题

  • ¥15 stata安慰剂检验作图但是真实值不出现在图上
  • ¥15 c程序不知道为什么得不到结果
  • ¥40 复杂的限制性的商函数处理
  • ¥15 程序不包含适用于入口点的静态Main方法
  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题