File types

This was another question in a skills evaluation test

Write a regular expression for the following code that will trim off the extension from a filename:

$ext = preg_replace(‘/xxxxx/’, ’’, $filename);

My solution:

I find regular expressions pretty tricky, so usually end up using an online tool like this:

In any case, my solution to this problem would most likely have been more like:

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.