In regular expressions the ^
and $
symbols are anchors to the beginning and end, respectively, of the line of text you are scanning. Try removing them from your pattern. Maybe try something like:
<?php
$str = '17:30 Football 18:30 Meal 20:00 Quiet';
$chars = preg_split('/(?:[01]\d|2[0-3]):(?:[0-5]\d)/', $str, -1, PREG_SPLIT_OFFSET_CAPTURE);
print_r ($chars);
?>
Don't forget that :
is a special character in regular expressions so it will need to be escaped.
By default all bracketed groups are remembered, but you can stop this with the ?:
syntax. I'm not entirely sure if that will cause an issue in PHP because I tested the expression with Python, but it should prevent the matches from being returned in the array.
You may also want to extend the expression slightly to automatically strip out the whitespace around your words:
$chars = preg_split('/\s*(?:[01]\d|2[0-3]):(?:[0-5]\d)\s*/', $str, -1, PREG_SPLIT_OFFSET_CAPTURE);
Hope this helps!