我有这个ereg()表达式:
^[0-9]{8}\T{1}[0-9]{2}\:[0-9]{2}\:[0-9]{2}$
如何将其转换为preg_match?
答案 0 :(得分:3)
表达式看起来很好,但你可以简化它:
^\d{8}\t\d{2}:\d{2}:\d{2}$
您的原始版本仍应使用preg
,但上面的内容更易于阅读和理解。几点说明:
[0-9]
与\d
{1}
是不必要的:
不需要转义答案 1 :(得分:2)
你走了。
$subject = 'the string i want to search through';
$pattern = '/^[0-9]{8}\T{1}[0-9]{2}\:[0-9]{2}\:[0-9]{2}$/';
$matches = array();
preg_match($pattern, $subject, $matches);
print_r($matches);