I have a string $subDay
like this:
Checkin 03:35 OL 270 DRS-ZRH 04:25-05:45 HSC, KRG, LEM, JOA OL 271 ZRH-DRS 06:45-08:15 HSC, KRG, LEM, JOA Checkout 08:45
and I want to add a new line ( ) with this command:
$subDay = preg_replace("/(Checkin [12][0-9]:[12][0-9])/", "$1
", $subDay);
I tested it with this RegexTester and my RegEx seems valid, but nothing happens.
Why?
Finally i used this RegEx:
/(Checkin ([01]{1}[0-9]{1}|[2]{1}[0-3]):[0-5]{1}[0-9]{1})/
It only matches double-digit valid times.
The character class [12]
only matches 1 or 2. It does not match the 0 in 03:35
. Try this instead:
/(Checkin [012][0-9]:[0-5][0-9])/
/(Checkin [012]{1}[0-9]{1}:[0-5]{1}[0-9]{1})/
Could be improved, because at the moment it will match 29, but you can play with it further if you need