There is no need for preg_match here. PHP has a wildcard comparison function, specifically made for such cases:
fnmatch()
And fnmatch('dir/*/file', 'dir/folder1/file') would likely already work for you. But beware that the * wildcard would likewise add further slashes, like preg_match would.