Code
<?php
$test = 'this is October 02, 2017 today';
$months="/(January | February | March | April | May | June | July | August |
September | October | November | December) [0-3] [0-9], 20 [0-9] +/";
preg_match($months,$test,$date);
var_dump($date);
?>
I want to get October02,2017
.
Output Results
array(2){[0]=>string(16) "Octover02, 2017"[1]=>string(7) "Octover"}
The target string has been removed, but the October
itself has also been removed.
Please tell me why this is happening.
Subpattern has a variety and simple ()
captures.The return of October
is also the result of the capture.Use (?:)
for subpatterns that you do not want to capture.
$months="/(?: January | February | March | April | May | June | August | September | October | October | November | December) [0-3][0-9], 20[0-9]+/";
© 2024 OneMinuteCode. All rights reserved.