^ (/D {2} ([02468] [048]) | ([13579] [26]) [// s]? (0? [13578]) | (1 [02]) [//-// s]? (0? [1-9]) | ([1-2] [0-9]) | (3 [01]) | (0? [469]) | (11) [//-// s]? (0? [1-9]) | ([1-2] [0-9]) | (30) | (0? 2 [/-// s]? (0? [1-9]) | ([1-2] [0-9]) | (/d {2} ([02468] [1235679]) | ([13579] [01345789]) [//-// s]? (0? [13578]) | (1 [02]) [//-// s]? (0? [1-9]) | ([1-2] [0-9]) | (3 [01]) | (0? [469]) | (11) [//-// s]? (0? [1-9]) | ([1-2] [0-9]) | (30) | (0? 2 [/-// s]? (0? [1-9]) | (1 [0-9]) | (2 [0-8]) (/s (0? [0-9]) | ([1-2] [0-3])/:( [0-5]? [0-9]) (/s) | (/:( [0-5]? [0-9])? $
C # code test:
Public class class1
{
Static void main (string [] ARGs)
{
// String RegEx = @ "^ (/d {2} ([02468] [048]) | ([13579] [26]) [/-// s]? (0? [13578]) | (1 [02]) [//-// s]? (0? [1-9]) | ([1-2] [0-9]) | (3 [01]) | (0? [469]) | (11) [//-// s]? (0? [1-9]) | ([1-2] [0-9]) | (30) | (0? 2 [/-// s]? (0? [1-9]) | ([1-2] [0-9]) | (/d {2} ([02468] [1235679]) | ([13579] [01345789]) [//-// s]? (0? [13578]) | (1 [02]) [//-// s]? (0? [1-9]) | ([1-2] [0-9]) | (3 [01]) | (0? [469]) | (11) [//-// s]? (0? [1-9]) | ([1-2] [0-9]) | (30) | (0? 2 [/-// s]? (0? [1-9]) | (1 [0-9]) | (2 [0-8]) (/s (0? [0-9]) | ([1-2] [0-3])/:( [0-5]? [0-9]) (/s) | (/:( [0-5]? [0-9])? $ ";
String RegEx = @ "^ (/d {2} ([02468] [048]) | ([13579] [26]) [/-// s]? (0? [13578]
) | (1 [02]) [//-// s]? (0? [1-9]) | ([1-2] [0-9]) | (3 [01]) | (0? [4
69]) | (11) [//-// s]? (0? [1-9]) | ([1-2] [0-9]) | (30) | (0? 2 [/-///
S]? (0? [1-9]) | ([1-2] [0-9]) | (/d {2} ([02468] [1235679]) | ([1
3579] [01345789]) [// s]? (0? [13578]) | (1 [02]) [//-// s]? ((
0? [1-9]) | ([1-2] [0-9]) | (3 [01]) | (0? [469]) | (11) [//-// s]? ((
0? [1-9]) | ([1-2] [0-9]) | (30) | (0? 2 [/-// s]? (0? [1-9]) | (1 [0-9]
) | (2 [0-8]) "; // Date part
RegEx + = @ "(/s (0? [0-9]) | ([1-2] [0-3])/:( [0-5]? [0-9]) (/s) | (/:( [0-5]? [0-9])? $ "; // Time part
System. text. regularexpressions. regexoptions Options = (system. text. regularexpressions. regexoptions. ignorepatternwhitespace | system. text. regularexpressions. regexoptions. multiline) | system. text. regularexpressions. regexoptions. ignorecase );
System. Text. regularexpressions. RegEx Reg = new system. Text. regularexpressions. RegEx (RegEx, options );
String S = "23:59:59 ";
System. Console. Out. writeline (S + "{0}", Reg. ismatch (s ));
S = "23:59:59 ";
System. Console. Out. writeline (S + "{0}", Reg. ismatch (s ));
S = "0:59:59 ";
System. Console. Out. writeline (S + "{0}", Reg. ismatch (s ));
S = ";
System. Console. Out. writeline (S + "{0}", Reg. ismatch (s ));
S = ";
System. Console. Out. writeline (S + "{0}", Reg. ismatch (s ));
S = "00:00:00 ";
System. Console. Out. writeline (S + "{0}", Reg. ismatch (s ));
}
}
// Java code Test
Import java. util. RegEx .*;
Class class1
{
Public static void main (string [] ARGs)
{
Pattern P = pattern. compile ("^ (// d {2} ([02468] [048]) | ([13579] [26]) [//-// s]? (0? [13578]) | (1 [02]) [//-///S]? (0? [1-9]) | ([1-2] [0-9]) | (3 [01]) | (0? [469]) | (11) [//-///S]? (0? [1-9]) | ([1-2] [0-9]) | (30) | (0? 2 [//-// s]? (0? [1-9]) | ([1-2] [0-9]) | (// d {2} ([02468] [1235679]) | ([13579] [01345789]) [//-// s]? (0? [13578]) | (1 [02]) [//-///S]? (0? [1-9]) | ([1-2] [0-9]) | (3 [01]) | (0? [469]) | (11) [//-///S]? (0? [1-9]) | ([1-2] [0-9]) | (30) | (0? 2 [//-// s]? (0? [1-9]) | (1 [0-9]) | (2 [0-8]) (// s (0? [0-9]) | ([1-2] [0-3]) // :( [0-5]? [0-9]) (// s) | (// :( [0-5]? [0-9])? $ ");
String S = "23:59:59 ";
System. Out. println (S + "" + P. matcher (s). Matches ());
S = "23:59:59 ";
System. Out. println (S + "" + P. matcher (s). Matches ());
S = "0:59:59 ";
System. Out. println (S + "" + P. matcher (s). Matches ());
S = ";
System. Out. println (S + "" + P. matcher (s). Matches ());
S = ";
System. Out. println (S + "" + P. matcher (s). Matches ());
S = "00:00:59 ";
System. Out. println (S + "" + P. matcher (s). Matches ());
}
}