diff --git wp-includes/functions.php wp-includes/functions.php
index 0afa50b..ef7ff90 100644
--- wp-includes/functions.php
+++ wp-includes/functions.php
@@ -3985,6 +3985,5 @@ function wp_auth_check( $response, $data ) {
 function get_tag_regex( $tag ) {
 	if ( empty( $tag ) )
 		return;
-
-	return sprintf( '(<%1$s[^>]*(?:/?>$|>[\s\S]*?</%1$s>))', tag_escape( $tag ) );
+	return sprintf( '<%1$s[^<]+(?:>(.*)<\/%1$s>|\s*\/>)', tag_escape( $tag ) );
 }
diff --git wp-includes/media.php wp-includes/media.php
index bd52867..55fed4b 100644
--- wp-includes/media.php
+++ wp-includes/media.php
@@ -2209,30 +2209,45 @@ function get_content_images( &$content, $html = true, $remove = false, $limit =
 	$tags = array();
 	$captions = array();
 
-	if ( $remove && preg_match_all( '/' . get_shortcode_regex() . '/s', $content, $matches, PREG_SET_ORDER ) && ! empty( $matches ) ) {
+	if ( preg_match_all( '/' . get_shortcode_regex() . '/s', $content, $matches, PREG_SET_ORDER ) && ! empty( $matches ) ) {
 		foreach ( $matches as $shortcode ) {
-			if ( 'caption' === $shortcode[2] )
+			if ( 'caption' === $shortcode[2] ) {
 				$captions[] = $shortcode[0];
+				if ( $html )
+					$tags[] = do_shortcode( $shortcode[0] );
+			}
+
+			if ( $limit > 0 && count( $tags ) >= $limit )
+				break;
 		}
 	}
 
-	if ( preg_match_all( '#<img[^>]+/?>#i', $content, $matches, PREG_SET_ORDER ) && ! empty( $matches ) ) {
-		foreach ( $matches as $tag ) {
-			$count = 1;
-			if ( $remove ) {
+	foreach ( array( 'a', 'img' ) as $tag ) {
+		if ( preg_match_all( '#' . get_tag_regex( $tag ) .  '#i', $content, $matches, PREG_SET_ORDER ) && ! empty( $matches ) ) {
+			foreach ( $matches as $node ) {
+				if ( ! strstr( $node[0], '<img ' ) )
+					continue;
+
+				$count = 1;
+				$found = false;
+
 				foreach ( $captions as $caption ) {
-					if ( strstr( $caption, $tag[0] ) ) {
-						$content = str_replace( $caption, '', $content, $count );
+					if ( strstr( $caption, $node[0] ) ) {
+						$found = true;
+						if ( $remove )
+							$content = str_replace( $caption, '', $content, $count );
 					}
 				}
 
-				$content = str_replace( $tag[0], '', $content, $count );
-			}
+				if ( $remove )
+					$content = str_replace( $node[0], '', $content, $count );
 
-			$tags[] = $tag[0];
+				if ( ! $found )
+					$tags[] = $node[0];
 
-			if ( $limit > 0 && count( $tags ) >= $limit )
-				break;
+				if ( $limit > 0 && count( $tags ) >= $limit )
+					break 2;
+			}
 		}
 	}
 
@@ -2400,6 +2415,7 @@ function get_the_post_format_image( $attached_size = 'full', &$post = null ) {
 	if ( isset( $post->format_content ) )
 		return $post->format_content;
 
+	$matched = false;
 	$meta = get_post_format_meta( $post->ID );
 
 	$link_fmt = '%s';
@@ -2426,7 +2442,7 @@ function get_the_post_format_image( $attached_size = 'full', &$post = null ) {
 		$sizes = get_intermediate_image_sizes();
 		$sizes[] = 'full'; // Add original image source.
 
-		$urls = array();
+		$urls = array( get_attachment_link( $media->ID ) );
 		foreach ( $sizes as $size ) {
 			$image = wp_get_attachment_image_src( $media->ID, $size );
 			if ( $image )
@@ -2444,8 +2460,11 @@ function get_the_post_format_image( $attached_size = 'full', &$post = null ) {
 			foreach ( $matches as $shortcode ) {
 				if ( 'caption' === $shortcode[2] ) {
 					foreach ( $urls as $url ) {
-						if ( strstr( $shortcode[0], $url ) )
+						if ( strstr( $shortcode[0], $url ) ) {
+							if ( ! $matched )
+								$matched = do_shortcode( $shortcode[0] );
 							$content = str_replace( $shortcode[0], '', $content, $count );
+						}
 					}
 				}
 			}
@@ -2455,16 +2474,25 @@ function get_the_post_format_image( $attached_size = 'full', &$post = null ) {
 			if ( preg_match_all( '#' . get_tag_regex( $tag ) . '#', $content, $matches, PREG_SET_ORDER ) && ! empty( $matches ) ) {
 				foreach ( $matches as $match ) {
 					foreach ( $urls as $url ) {
-						if ( strstr( $match[0], $url ) )
+						if ( strstr( $match[0], $url ) ) {
+							if ( ! $matched )
+								$matched = $match[0];
 							$content = str_replace( $match[0], '', $content, $count );
+						}
 					}
 				}
 			}
 		}
 
 		$post->split_content = $content;
-		$image = wp_get_attachment_image( $media->ID, $attached_size );
-		$post->format_content = sprintf( $link_fmt, $image );
+		if ( ! $matched ) {
+			$image = wp_get_attachment_image( $media->ID, $attached_size );
+			$post->format_content = sprintf( $link_fmt, $image );
+		} else {
+			$post->format_content = $matched;
+			if ( ! empty( $meta['url'] ) && false === stripos( $matched, '<a ' ) )
+				$post->format_content = sprintf( $link_fmt, $matched );
+		}
 		return $post->format_content;
 	}
 
