lib/ImageHelper.php
protected static function process_delete_generated_files( $filename, $ext, $dir, $search_pattern, $match_pattern = null ) {
		$searcher = '/'.$filename.$search_pattern;
		$files = glob($dir.$searcher);
		if ( $files === false || empty($files) ) {
			return;
		}
		foreach ( $files as $found_file ) {
			$pattern = '/'.preg_quote($dir, '/').'\/'.preg_quote($filename, '/').$match_pattern.preg_quote($ext, '/').'/';
			$match = preg_match($pattern, $found_file);
			if ( !$match_pattern || $match ) {
				unlink($found_file);
			}
		}
	}
protected static function process_delete_generated_files( $filename, $ext, $dir, $search_pattern, $match_pattern = null ) {
		$searcher = '/'.$filename.$search_pattern;
		$files = glob($dir.$searcher);
		if ( $files === false || empty($files) ) {
			return;
		}
		foreach ( $files as $found_file ) {
			$pattern = '/'.preg_quote($dir, '/').'\/'.preg_quote($filename, '/').$match_pattern.preg_quote($ext, '/').'/';
			$match = preg_match($pattern, $found_file);
			if ( !$match_pattern || $match ) {
				unlink($found_file);
			}
		}
	}
protected static function process_delete_generated_files ( $ filename , $ ext , $ dir , $ search_pattern , $ match_pattern = null ) { $ searcher = '/' . $ filename . $ search_pattern ; $ files = glob ( $ dir . $ searcher ) ; if ( $ files === false || empty ( $ files ) ) { return ; } foreach ( $ files as $ found_file ) { $ pattern = '/' . preg_quote ( $ dir , '/' ) . '\/' . preg_quote ( $ filename , '/' ) . $ match_pattern . preg_quote ( $ ext , '/' ) . '/' ; $ match = preg_match ( $ pattern , $ found_file ) ; if ( ! $ match_pattern || $ match ) { unlink ( $ found_file ) ; } } }
Deletes resized versions of the supplied file name.
So if passed a value like my-pic.jpg, this function will delete my-pic-500x200-c-left.jpg, my-pic-400x400-c-default.jpg, etc.

keeping these here so I know what the hell we're matching
$match = preg_match("/\/srv\/www\/wordpress-develop\/src\/wp-content\/uploads\/2014\/05\/$filename-[0-9]*x[0-9]*-c-[a-z]*.jpg/", $found_file);
$match = preg_match("/\/srv\/www\/wordpress-develop\/src\/wp-content\/uploads\/2014\/05\/arch-[0-9]*x[0-9]*-c-[a-z]*.jpg/", $filename);

@param string 	$filename   ex: my-pic
@param string 	$ext ex: jpg
@param string 	$dir var/www/wp-content/uploads/2015/
@param string 	$search_pattern pattern of files to pluck from
@param string 	$match_pattern pattern of files to go forth and delete
Deletes resized versions of the supplied file name . So if passed a value like my - pic . jpg this function will delete my - pic - 500x200 - c - left . jpg my - pic - 400x400 - c - default . jpg etc .