Index: wp-includes/post.php
===================================================================
--- wp-includes/post.php	(revision 23303)
+++ wp-includes/post.php	(working copy)
@@ -3118,7 +3118,7 @@
 		$check_sql = "SELECT post_name FROM $wpdb->posts WHERE post_name = %s AND post_type IN ( '" . implode( "', '", esc_sql( $hierarchical_post_types ) ) . "' ) AND ID != %d AND post_parent = %d LIMIT 1";
 		$post_name_check = $wpdb->get_var( $wpdb->prepare( $check_sql, $slug, $post_ID, $post_parent ) );
 
-		if ( $post_name_check || in_array( $slug, $feeds ) || preg_match( "@^($wp_rewrite->pagination_base)?\d+$@", $slug )  || apply_filters( 'wp_unique_post_slug_is_bad_hierarchical_slug', false, $slug, $post_type, $post_parent ) ) {
+		if ( $post_name_check || in_array( $slug, $feeds ) || preg_match( "@^/$wp_rewrite->pagination_base/\d+$@", $slug )  || apply_filters( 'wp_unique_post_slug_is_bad_hierarchical_slug', false, $slug, $post_type, $post_parent ) ) {
 			$suffix = 2;
 			do {
 				$alt_post_name = substr( $slug, 0, 200 - ( strlen( $suffix ) + 1 ) ) . "-$suffix";
Index: wp-includes/link-template.php
===================================================================
--- wp-includes/link-template.php	(revision 23303)
+++ wp-includes/link-template.php	(working copy)
@@ -1448,7 +1448,7 @@
 			$query_string = '';
 		}
 
-		$request = preg_replace( "|$wp_rewrite->pagination_base/\d+/?$|", '', $request);
+		$request = preg_replace( "|/$wp_rewrite->pagination_base/\d+/?$|", '', $request);
 		$request = preg_replace( '|^index\.php|i', '', $request);
 		$request = ltrim($request, '/');
 
@@ -1464,7 +1464,7 @@
 		$result = $base . $request . $query_string;
 	}
 
-	$result = apply_filters('get_pagenum_link', $result);
+	$result = apply_filters('get_pagenum_link', $result, $pagenum);
 
 	if ( $escape )
 		return esc_url( $result );
Index: wp-includes/rewrite.php
===================================================================
--- wp-includes/rewrite.php	(revision 23303)
+++ wp-includes/rewrite.php	(working copy)
@@ -1232,12 +1232,12 @@
 
 		//$feedregex is identical but with /feed/ added on as well, so URLs like <permalink>/feed/atom
 		//and <permalink>/atom are both possible
-		$feedregex = $this->feed_base . '/' . $feedregex2;
+		$feedregex = '/'.$this->feed_base . '/' . $feedregex2;
 
 		//build a regex to match the trackback and page/xx parts of URLs
-		$trackbackregex = 'trackback/?$';
-		$pageregex = $this->pagination_base . '/?([0-9]{1,})/?$';
-		$commentregex = 'comment-page-([0-9]{1,})/?$';
+		$trackbackregex = '/trackback/?$';
+		$pageregex = '/'.$this->pagination_base . '/?([0-9]{1,})/?$';
+		$commentregex = '/comment-page-([0-9]{1,})/?$';
 
 		//build up an array of endpoint regexes to append => queries to append
 		if ( $endpoints ) {
@@ -1297,7 +1297,7 @@
 			$struct = ltrim($struct, '/');
 
 			//replace tags with regexes
-			$match = str_replace($this->rewritecode, $this->rewritereplace, $struct);
+			$match = untrailingslashit(str_replace($this->rewritecode, $this->rewritereplace, $struct));
 
 			//make a list of tags, and store how many there are in $num_toks
 			$num_toks = preg_match_all('/%.+?%/', $struct, $toks);
Index: wp-includes/canonical.php
===================================================================
--- wp-includes/canonical.php	(revision 23303)
+++ wp-includes/canonical.php	(working copy)
@@ -220,9 +220,9 @@
 
 		// paging and feeds
 		if ( get_query_var('paged') || is_feed() || get_query_var('cpage') ) {
-			while ( preg_match( "#/$wp_rewrite->pagination_base/?[0-9]+?(/+)?$#", $redirect['path'] ) || preg_match( '#/(comments/?)?(feed|rss|rdf|atom|rss2)(/+)?$#', $redirect['path'] ) || preg_match( '#/comment-page-[0-9]+(/+)?$#', $redirect['path'] ) ) {
+			while ( preg_match( "#/$wp_rewrite->pagination_base/[0-9]+?(/+)?$#", $redirect['path'] ) || preg_match( '#/(comments/?)?(feed|rss|rdf|atom|rss2)(/+)?$#', $redirect['path'] ) || preg_match( '#/comment-page-[0-9]+(/+)?$#', $redirect['path'] ) ) {
 				// Strip off paging and feed
-				$redirect['path'] = preg_replace("#/$wp_rewrite->pagination_base/?[0-9]+?(/+)?$#", '/', $redirect['path']); // strip off any existing paging
+				$redirect['path'] = preg_replace("#/$wp_rewrite->pagination_base/[0-9]+?(/+)?$#", '/', $redirect['path']); // strip off any existing paging
 				$redirect['path'] = preg_replace('#/(comments/?)?(feed|rss2?|rdf|atom)(/+|$)#', '/', $redirect['path']); // strip off feed endings
 				$redirect['path'] = preg_replace('#/comment-page-[0-9]+?(/+)?$#', '/', $redirect['path']); // strip off any existing comment paging
 			}
