Hi guys,
I am poor at regular expression, and I need something that I am sure can be achieved with regular expression but just that I cannot figure out how.
I need to pick out file all filesnames that ends with .jpg or .gif, but the left side of the filename (left side of the . ) cannot end with tn.
For example, it needs to pick out filenames such as
hello123.jpg
whatisthis.gif
034984.jpg
but not
hello123tn.jpg
toirkrtn.gif
019a3tn4tn.gif
I have constructed the regular expression that picks out all the jpg/gif files, but that is it. I do have a work around by using explode then substr which works just fine, but i rather keep it simple with just regular expression.
This is what I have now, the dodgy method using explode and substr:
while($file_name = readdir($dir_handle)) {
if($file_name != "." && $file_name != ".." && filetype($file_name)!="dir") {
if(preg_match("/(JPG|JPEG|GIF|JPE)$/i", $file_name)) {
$parts = explode(".", $file_name);
if(substr($parts[0], -2)!="tn") {
$dirArray[] = $file_name;
}
}
}
}
I hope someone can help me out 🙁