regex - Regular expression for 24-hour format in Perl -
I have a scalar variable, I have some string value. I now want to write a pattern match that checks Whether the value is in the correct format or not.
my $ var = "2340"; Correct format My $ var = "23:40"; I tried to do this but did not work for me:
/ ^ (0 [1- 9] | 1 [012]) ( : [0 -5] \ d Time format can be 00:00 (format will be 2 digits first: and then 2 digits :)
everything , Even under such circumstances They are very weird and it can understand a lot more to use something else.
In your case, off-the-counter code (some syntax errors may not have been tested):
if ($ var = ~ / (\ d \ d): (\ d \ d) /) {my $ hour = $ 1; my $ min = $ 2; if ($ hour & Gt; 23 || $ min> 59) {Print "Numbers Out of the Border!";} And {# Yes, Valid!}} {Print "Invalid Date Format!";}
Comments
Post a Comment