I can replace your version: $basename = preg_replace( '/^.+[\\\\\\/]/', '', $fileName ); with: $basename = preg_replace( "/^.+\//", '', $fileName ); and all of your tests still pass. Can you put in a test that fails with the simpler version?