I know there are many regex questions on Stackoverflow and I've studied my code again and again but as a newbie to regex and PHP in general I just don't understand. I have a list of file names such as
1000032842_WMN_2150_cv.pdf
1000041148_BKO_111_SY_bj.pdf
000048316_ED_3100_AMW_2_a.pdf
1000041231_HF_210_WPO_cr.pdf
I am trying to extract the last lowercase characters only: cv, bj, a, cr
I am using the following regex to try and do that: [a-z.]+$
1) Is the regex correct ?
2) What would be the right php function to use to extra the portion of these strings ?
I have used preg_match, preg_split, but I am not sure which one I should really use. I THINK preg_split is the correct function.
$url = "1000036112_GKV_35_VM_32_a.pdf";
$url = preg_split('/[a-z.]+$/', $url);
print_r ($url);
but [1] is empty.
Array ( [0] => 1000036112_GKV_35_VM_32_ [1] => )
UPDATE EDIT
The following gives a list of int 0, int 1, etc.
<?php
$filename = "urls.csv";
$handle = fopen($filename, "r");
if ($handle !== FALSE) {
while (($data=fgetcsv($handle,99999,',')) !== FALSE) {
$url = $data[1];
var_dump (preg_match_all('/_([a-z]{1,2})\./', $url));
}
}
?>
