Index: wp-includes/formatting.php
===================================================================
--- wp-includes/formatting.php	(revision 12292)
+++ wp-includes/formatting.php	(working copy)
@@ -216,7 +216,7 @@
 	if (strpos($pee, '<pre') !== false)
 		$pee = preg_replace_callback('!(<pre[^>]*>)(.*?)</pre>!is', 'clean_pre', $pee );
 	$pee = preg_replace( "|\n</p>$|", '</p>', $pee );
-	$pee = preg_replace('/<p>\s*?(' . get_shortcode_regex() . ')\s*<\/p>/s', '$1', $pee); // don't auto-p wrap shortcodes that stand alone
+	$pee = preg_replace('/<p>\s*?(' . get_shortcode_regex(1) . ')\s*<\/p>/s', '$1', $pee); // don't auto-p wrap shortcodes that stand alone
 
 	return $pee;
 }
Index: wp-includes/shortcodes.php
===================================================================
--- wp-includes/shortcodes.php	(revision 12292)
+++ wp-includes/shortcodes.php	(working copy)
@@ -168,15 +168,18 @@
  * @since 2.5
  * @uses $shortcode_tags
  *
+ * @param int Backreference nesting context for this regexp.
  * @return string The shortcode search regular expression
  */
-function get_shortcode_regex() {
+function get_shortcode_regex($nesting = 0) {
 	global $shortcode_tags;
 	$tagnames = array_keys($shortcode_tags);
 	$tagregexp = join( '|', array_map('preg_quote', $tagnames) );
 
+    $backref = 2 + (int) $nesting;
+
 	// WARNING! Do not change this regex without changing do_shortcode_tag() and strip_shortcodes()
-	return '(.?)\[('.$tagregexp.')\b(.*?)(?:(\/))?\](?:(.+?)\[\/\2\])?(.?)';
+	return '(.?)\\[('.$tagregexp.')\\b(.*?)\\/?\\](?:(.+?)\\[\\/\\'.$backref.'\\])?(.?)';
 }
 
 /**
@@ -194,19 +197,19 @@
 	global $shortcode_tags;
 
 	// allow [[foo]] syntax for escaping a tag
-	if ($m[1] == '[' && $m[6] == ']') {
+	if ($m[1] == '[' && $m[5] == ']') {
 		return substr($m[0], 1, -1);
 	}
 
 	$tag = $m[2];
 	$attr = shortcode_parse_atts($m[3]);
 
-	if ( isset($m[5]) ) {
+	if ( isset($m[4]) ) {
 		// enclosing tag - extra parameter
-		return $m[1] . call_user_func($shortcode_tags[$tag], $attr, $m[5], $m[2]) . $m[6];
+		return $m[1] . call_user_func($shortcode_tags[$tag], $attr, $m[4], $m[2]) . $m[5];
 	} else {
 		// self-closing tag
-		return $m[1] . call_user_func($shortcode_tags[$tag], $attr, NULL, $m[2]) . $m[6];
+		return $m[1] . call_user_func($shortcode_tags[$tag], $attr, NULL, $m[2]) . $m[5];
 	}
 }
 
