diff --git src/wp-includes/class-wp-theme.php src/wp-includes/class-wp-theme.php
index 8b3661a..0053fe9 100644
--- src/wp-includes/class-wp-theme.php
+++ src/wp-includes/class-wp-theme.php
@@ -1033,7 +1033,7 @@ final class WP_Theme implements ArrayAccess {
 				}
 
 				$types = array( 'page' );
-				if ( preg_match( '|Template Post Type:(.*)$|mi', file_get_contents( $full_path ), $type ) ) {
+				if ( preg_match( '|Template Post Type:(.*)\.?\s*$|miU', file_get_contents( $full_path ), $type ) ) {
 					$types = explode( ',', _cleanup_header_comment( $type[1] ) );
 				}
 
diff --git tests/phpunit/data/themedir1/page-templates/38766/no-trailing-period-post-types.php tests/phpunit/data/themedir1/page-templates/38766/no-trailing-period-post-types.php
new file mode 100644
index 0000000..2b68671
--- /dev/null
+++ tests/phpunit/data/themedir1/page-templates/38766/no-trailing-period-post-types.php
@@ -0,0 +1,5 @@
+<?php
+/*
+   Template Name: No Trailing Period
+   Template Post Type: period, full-stop
+ */
diff --git tests/phpunit/data/themedir1/page-templates/38766/trailing-period-post-types.php tests/phpunit/data/themedir1/page-templates/38766/trailing-period-post-types.php
new file mode 100644
index 0000000..594b677
--- /dev/null
+++ tests/phpunit/data/themedir1/page-templates/38766/trailing-period-post-types.php
@@ -0,0 +1,7 @@
+<?php
+/*
+   Template Name: Trailing Period.
+   Template Post Type: period, full-stop.
+
+   Text following the meaningful line to the modifier behaves as expected.
+ */
diff --git tests/phpunit/tests/admin/includesTheme.php tests/phpunit/tests/admin/includesTheme.php
index 5319006..6a11a7a 100644
--- tests/phpunit/tests/admin/includesTheme.php
+++ tests/phpunit/tests/admin/includesTheme.php
@@ -87,6 +87,25 @@ class Tests_Admin_includesTheme extends WP_UnitTestCase {
 	}
 
 	/**
+	 * @ticket 38766
+	 */
+	function test_page_templates_for_post_types_with_trailing_periods() {
+		$theme = wp_get_theme( 'page-templates' );
+		$this->assertNotEmpty( $theme );
+
+		switch_theme( $theme['Template'], $theme['Stylesheet'] );
+
+		$this->assertEqualSetsWithIndex( array(
+			'No Trailing Period' => '38766/no-trailing-period-post-types.php',
+			'Trailing Period.' => '38766/trailing-period-post-types.php',
+		), get_page_templates( null, 'period' ) );
+		$this->assertEqualSetsWithIndex( array(
+			'No Trailing Period' => '38766/no-trailing-period-post-types.php',
+			'Trailing Period.' => '38766/trailing-period-post-types.php',
+		), get_page_templates( null, 'full-stop' ) );
+	}
+
+	/**
 	 * @ticket 38696
 	 */
 	function test_page_templates_child_theme() {
