[英]PHP - Regex to find [digit][digit][colon][digit][digit]
I'm attempting to extract [digit][digit][colon][digit][digit] from a string if it is present. 我正在尝试从字符串中提取[digit] [digit] [colon] [digit] [digit](如果存在)。 The Regex should match: 正则表达式应匹配:
02:59
03:24
So far I've got quite lost, though I've realised \\d
will return me a single digit, and \\d{2}
should find me 2, but I've got stuck with adding in the separator :
and finding 2 more digits to fit into my preg_match
: 到目前为止,我已经迷路了,尽管我已经意识到\\d
将返回一位数字,并且\\d{2}
应该找到2,但是我仍然坚持添加分隔符:
并找到另外2个适合我的preg_match
数字:
$trackTime = preg_match($regexEludingMe, $track, $matches);
Example $track
is: 10. Break Your Heart 03:42
should match 03:42
示例$track
是: 10. Break Your Heart 03:42
应该匹配03:42
Just add the separator :
and duplicate the first part that you've already figured out \\d{2}:\\d{2}
. 只需添加分隔符:
然后复制您已经弄清楚\\d{2}:\\d{2}
的第一部分。 Don't forget delimiters: 不要忘记定界符:
preg_match('/\d{2}:\d{2}/', $track, $trackTime);
print_r($trackTime);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.