Possible Duplicate:
Converting ereg expressions to preg
I have this ereg() expression:
^[0-9]{8}\T{1}[0-9]{2}\:[0-9]{2}\:[0-9]{2}$
How can I convert it to the preg_match one?
Possible Duplicate:
Converting ereg expressions to preg
I have this ereg() expression:
^[0-9]{8}\T{1}[0-9]{2}\:[0-9]{2}\:[0-9]{2}$
How can I convert it to the preg_match one?
The expression looks fine, but you can simplify it:
^\d{8}\t\d{2}:\d{2}:\d{2}$
Your original one should still work with preg
, but the one above is simpler to read and understand. A few notes:
[0-9]
is the same as \d
{1}
is unnecessary:
does not need escaping Here you go.
$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);