Index: src/wp-includes/class-wp-embed.php
===================================================================
--- src/wp-includes/class-wp-embed.php	(revision 27517)
+++ src/wp-includes/class-wp-embed.php	(working copy)
@@ -289,7 +289,9 @@
 	 * @return string Potentially modified $content.
 	 */
 	function autoembed( $content ) {
-		return preg_replace_callback( '|^\s*(https?://[^\s"]+)\s*$|im', array( $this, 'autoembed_callback' ), $content );
+
+        return preg_replace_callback( '|(?<!")(?<!"\s)(https?:\/\/[^\s"\[<]+)|im', array( $this, 'autoembed_callback' ), $content );
+
 	}
 
 	/**
Index: tests/phpunit/tests/media.php
===================================================================
--- tests/phpunit/tests/media.php	(revision 27517)
+++ tests/phpunit/tests/media.php	(working copy)
@@ -437,4 +437,121 @@
 		$this->assertTrue( has_image_size( 'test-size' ) );
 	}
 
+    /**
+     * @ticket 25387
+     * Testing variants of Autoembeds within paragraphs and surrounded by other text/markup
+     */
+    function test_autoembed_inline_paragraph() {
+
+        $embed = new WP_Embed();
+        $url1 = '<p>
+http://www.youtube.com/watch?v=ZJrP9irrLZk
+</p>';
+        $embed_oembed1 = <<<VIDEOWITHPTAG
+<p>http://www.youtube.com/watch?v=ZJrP9irrLZk</p>
+VIDEOWITHPTAG;
+
+        $url2 = '<p>test
+
+http://www.youtube.com/watch?v=ZJrP9irrLZk
+
+test</p>';
+        $embed_oembed2 = <<<VIDEOWITHPTAGANDTEXT
+<p>test
+http://www.youtube.com/watch?v=ZJrP9irrLZk
+test</p>
+VIDEOWITHPTAGANDTEXT;
+
+        $url3 = 'http://www.youtube.com/watch?v=ZJrP9irrLZk';
+        $embed_oembed3 = <<<VIDEONOEMBED
+http://www.youtube.com/watch?v=ZJrP9irrLZk
+VIDEONOEMBED;
+
+        $embed_oembed4 = <<<VIDEOEMBEDWITHSPACE
+[embed] http://vimeo.com/85107599[/embed]
+VIDEOEMBEDWITHSPACE;
+        $url4 = 'http://vimeo.com/85107599';
+
+        $embed_oembed5 = <<<LINKWITHSPACE
+<a href=" http://www.youtube.com/watch?v=ZJrP9irrLZk">Video link not embedded because of space within href attribute</a>
+LINKWITHSPACE;
+        $url5 = '<a href=" http://www.youtube.com/watch?v=ZJrP9irrLZk">Video link not embedded because of space within href attribute</a>';
+
+        $embed_oembed6 = <<<URLSWHITESPACE
+So, YouTube video firsthttp://www.youtube.com/watch?v=ZJrP9irrLZk Now, after YouTube comes Vimeo video secondhttp://vimeo.com/85107599 and after Vimeo
+URLSWHITESPACE;
+        $url6 = 'So, YouTube video first
+http://www.youtube.com/watch?v=ZJrP9irrLZk
+ Now, after YouTube comes Vimeo video second
+http://vimeo.com/85107599
+ and after Vimeo';
+
+        $embed_oembed7 = <<<STANDARDANCHORLINK
+<a href="http://www.youtube.com/watch?v=ZJrP9irrLZk">Sample this should be a link</a>
+STANDARDANCHORLINK;
+        $url7 = '<a href="http://www.youtube.com/watch?v=ZJrP9irrLZk">Sample this should be a link</a>';
+
+        $embed_oembed8 = <<<URLWITHMARKUP
+Video url surrounded by span styled with border and background
+<span style="border: 5px solid gray; background: #0000cc;">http://www.youtube.com/watch?v=ZJrP9irrLZk</span>
+URLWITHMARKUP;
+        $url8 = 'Video url surrounded by span styled with border and background
+<span style="border: 5px solid gray; background: #0000cc;">
+http://www.youtube.com/watch?v=ZJrP9irrLZk
+</span>';
+
+        $embed_oembed9 = <<<EMBEDVIDEOPRESS
+VideoPress wrapped in [ e m b e d ] tags
+[embed]http://videos.videopress.com/EsBeI509/video-4f0ea27927_dvd.mp4[/embed]
+EMBEDVIDEOPRESS;
+        $url9 = 'VideoPress wrapped in [ e m b e d ] tags
+[embed]
+http://videos.videopress.com/EsBeI509/video-4f0ea27927_dvd.mp4
+[/embed]';
+
+        $embed_oembed10 = <<<FLICKRFULLURL
+<p>http://www.flickr.com/photos/seanhayes/270924038/</p>
+FLICKRFULLURL;
+        $url10 = '<p>
+http://www.flickr.com/photos/seanhayes/270924038/
+</p>';
+
+        $embed_oembed11 = <<<DAILYMOTIONFULLURL
+<p>http://www.flickr.com/photos/seanhayes/270924038/</p>
+DAILYMOTIONFULLURL;
+        $url11 = '<p>http://www.dailymotion.com/video/x1gl4rz_the-rolling-stones-rock-shanghai_news</p>';
+
+        $content1 = $embed->autoembed( $embed_oembed1 );
+        $this->assertContains( $url1, $content1 );
+
+        $content2 = $embed->autoembed( $embed_oembed2 );
+        $this->assertContains( $url2, $content2 );
+
+        $content3 = $embed->autoembed( $embed_oembed3 );
+        $this->assertContains( $url3, $content3 );
+
+        $content4 = $embed->autoembed( $embed_oembed4 );
+        $this->assertContains( $url4, $content4 );
+
+        $content5 = $embed->autoembed( $embed_oembed5 );
+        $this->assertEquals( $url5, $content5 );
+
+        $content6 = $embed->autoembed( $embed_oembed6 );
+        $this->assertContains( $url6, $content6 );
+
+        $content7 = $embed->autoembed( $embed_oembed7 );
+        $this->assertEquals( $url7, $content7 );
+
+        $content8 = $embed->autoembed( $embed_oembed8 );
+        $this->assertEquals( $url8, $content8 );
+
+        $content9 = $embed->autoembed( $embed_oembed9 );
+        $this->assertContains( $url9, $content9 );
+
+        $content10 = $embed->autoembed( $embed_oembed10 );
+        $this->assertEquals( $url10, $content10 );
+
+        $content11 = $embed->autoembed( $embed_oembed11 );
+        $this->assertEquals( $url11, $content11 );
+    }
 }
