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