diff --git a/lib/private/files/view.php b/lib/private/files/view.php
index cb3c05d2bca152b6452e5d8a34436d31a9e17125..1a6be73d5bb5c65b8060d503b2bedf9286d9f2c1 100644
--- a/lib/private/files/view.php
+++ b/lib/private/files/view.php
@@ -1656,11 +1656,11 @@ class View {
 		}
 
 		// verify database - e.g. mysql only 3-byte chars
-		if (preg_match('%^(?:
+		if (preg_match('%(?:
       \xF0[\x90-\xBF][\x80-\xBF]{2}      # planes 1-3
     | [\xF1-\xF3][\x80-\xBF]{3}          # planes 4-15
     | \xF4[\x80-\x8F][\x80-\xBF]{2}      # plane 16
-)*$%xs', $fileName)) {
+)%xs', $fileName)) {
 			throw new InvalidPathException($l10n->t('4-byte characters are not supported in file names'));
 		}
 
diff --git a/tests/lib/files/pathverificationtest.php b/tests/lib/files/pathverificationtest.php
index b59aceba7b1fb729e894da0f495b9b1f1fa546fd..f7d5f057c14a6ee95846c68891e6dccf9a48ce27 100644
--- a/tests/lib/files/pathverificationtest.php
+++ b/tests/lib/files/pathverificationtest.php
@@ -83,6 +83,8 @@ class PathVerification extends \Test\TestCase {
 		return [
 			// this is the monkey emoji - http://en.wikipedia.org/w/index.php?title=%F0%9F%90%B5&redirect=no
 			['🐵'],
+			['🐵.txt'],
+			['txt.💩'],
 		];
 	}