regex - Conditional RgEx with PHP preg_match_all -
just have select conditional regex.
here have problem....
i want select time string 02:00 not quotation marks "02:00" or '02:00'
i using select 02:00 or 2:00 regex
$pattern = '/(\d{2}:\d{2})|(\d{1}:\d{2})/'; preg_match_all($pattern,$content, $matches);
but selecting "02:00" or '02:00' not sure regex use skip time string.
i got http://www.regular-expressions.info/conditional.html not sure how make regex :(
please me out.
update
thanks lucas trzesniewski , great help.
i resolved issue php code.
$pattern = '/(?!["\'])\b\d{1,2}:\d{2}\b(?!["\'])/'; preg_match_all($pattern,$content, $matches);
conditionals won't in case.
the simplest way use lookarounds:
(?<!["'])\b\d{1,2}:\d{2}\b(?!["'])
(?<!["'])
(negative lookbehind) make sure preceding character not single or double quote(?!["'])
(negative lookahead) same following character
Comments
Post a Comment