I am trying to write a regular expression to validate file names on a file system.
Examples of valid file names are
The logic behind valid is the image starts with tapa followed by an underscore. Then the domain name followed by _ the tld (com, org, net)
Thanks
preg_match('/^tapa_[a-z0-9-_]+?_(com|org|net)\.png$/', $string);
That ought to do it (tested). If you want to match capital letters too, add the i
(case insensitive) flag like this:
preg_match('/^tapa_[a-z0-9-_]+?_(com|org|net)\.png$/i', $string);
For a graphical representation of how this works, you can paste it in here: http://strfriend.com
^tapa_[a-zA-Z0-9\-_]+_(com|org|net)\.png$
should work for you.
You could try:
preg_match('/^tapa_.+_(com|org|net)\.png$/', $filename);