Can someone guide me in the direction on how to get a RegEx pattern matching the following possibilities for C#?:
- RegEx using 4 parameters
- First 2 params can get the star (*) character as value
- 1st param, if not a *, needs to be an int between (including) 0 and 6 (single digit)
- 2st param, if not a *, needs to be an int between (including) 01 and 31 (double digit)
- 3rd param needs to be an int between (incl开发者_如何学运维uding) 00 and 23 (double digit)
- 4th param needs to be an int of 00, 15, 30 or 45 (double digit)
I also need to check if a given string (same format as mentioned) matches the current date time in the same format. If data is "* 5 15 30", and current date formatted is "2 5 15 30", matching check would tell me it matches. If data is "0 5 15 30", and current date formatted is "2 5 15 30", matching check would tell me it doesn't matches.
Thanks
This should work for you if your parameters are separated by some amount of white-space in the string:
(\*|[0-6])\s+(\*|[0-2]\d|3[01])\s+([01]\d|2[0-3])\s+(00|15|30|45)
精彩评论