Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 字符串“hh:mm:ss tt”的正则表达式_Regex_C# 4.0 - Fatal编程技术网

Regex 字符串“hh:mm:ss tt”的正则表达式

Regex 字符串“hh:mm:ss tt”的正则表达式,regex,c#-4.0,Regex,C# 4.0,如何限制字符串具有以下值之一?它们都不区分大小写: hh:mm: hh:mm:ss hh:mm tt hh:mm:ss tt 我尝试过这个正则表达式^[hh:mm][:ss]?[tt]?[:ss tt]?$,但它没有给我想要的结果。有什么帮助吗?我想你混淆了角色类[ab]和组abc。 请尝试使用此正则表达式: ^(hh:mm)(?::ss)?(?: tt)?$ 其中: ^ : begining of string (hh:mm) : capture group th

如何限制字符串具有以下值之一?它们都不区分大小写:

hh:mm: hh:mm:ss hh:mm tt hh:mm:ss tt
我尝试过这个正则表达式^[hh:mm][:ss]?[tt]?[:ss tt]?$,但它没有给我想要的结果。有什么帮助吗?

我想你混淆了角色类[ab]和组abc。 请尝试使用此正则表达式:

^(hh:mm)(?::ss)?(?: tt)?$
其中:

^           : begining of string
  (hh:mm)   : capture group that contains 'hh:mm'
  (?::ss)?  : optional non capture group that contains ':ss'
  (?: tt)?  : optional non capture group that contains ' tt'
$           : end of string

您正在寻找正则表达式以字符串形式定义日期格式吗?是的,但仅限于时间格式。我正在使用第三方控件,该控件具有掩码属性。时间格式可由用户配置。我只需要选择该时间格式并将其提供给控件的Mask属性。但是,如果提供的格式不正确,将用默认时间格式替换。因此,为了验证提供的时间格式,我需要正则表达式。