regex - PHP preg_grep not working? -
$filenamematchregex = ^a-[0-9]*_b-[0-9]*_c-.*(_d-on)?_((19|20)\d\d[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01]))-[0-9]*\.csv$ $filenames = array ( [0] => index.html [1] => a-34234234_b-3271_c-123_d-on_2013-08-12-10.csv [2] => a-52342345_b-3271_c-123_d-on_2013-08-12-11.csv [3] => a-8764453_b-3271_c-123_d-on_2013-08-12-12.csv [4] => a-7654334_b-3271_c-1234_d-on_2013-08-12-4.csv [5] => a-3435_b-3271_c-23re_d-on_2013-08-12-5.csv [6] => a-909876_b-3271_c-wef2r2_d-on_2013-08-12-6.csv [7] => a-345456_b-3271_c-23rwef_d-on_2013-08-12-7.csv [8] => a-98765_b-3271_c-23ref_d-on_2013-08-12-8.csv [9] => a-098765_b-3271_c-wef2r_d-on_2013-08-12-9.csv ) $matchingfilenames = preg_grep ("/".$filenamematchregex."/", $filenames);
this works here...i match on 1-9: regex tester
its working fine me
$filenames = explode(',', "index.html,a-34234234_b-3271_c-123_d-on_2013-08-12-10.csv,a-52342345_b-3271_c-123_d-on_2013-08-12-11.csv,a-8764453_b-3271_c-123_d-on_2013-08-12-12.csv,a-7654334_b-3271_c-1234_d-on_2013-08-12-4.csv,a-3435_b-3271_c-23re_d-on_2013-08-12-5.csv,a-909876_b-3271_c-wef2r2_d-on_2013-08-12-6.csv,a-345456_b-3271_c-23rwef_d-on_2013-08-12-7.csv,a-98765_b-3271_c-23ref_d-on_2013-08-12-8.csv,a-098765_b-3271_c-wef2r_d-on_2013-08-12-9.csv"); $filenamematchregex = '^a-[0-9]*_b-[0-9]*_c-.*(_d-on)?_((19|20)\d\d[- /.](0[1-9]|1[012])[- /.](0[1-9]|[12][0-9]|3[01]))-[0-9]*\.csv$'; $matchingfilenames = preg_grep ("#".$filenamematchregex."#", $filenames); print_r($filenames); print_r($matchingfilenames);
but used '#' around regexp delimiter, regexp included '/', proberly need escape '/' or chose better delimiter
Comments
Post a Comment