diff --git a/django/core/urlresolvers.py b/django/core/urlresolvers.py
index 52d9090..0db5f11 100644
--- a/django/core/urlresolvers.py
+++ b/django/core/urlresolvers.py
@@ -302,7 +302,8 @@ class RegexURLResolver(object):
     def resolve500(self):
         return self._resolve_special('500')
 
-    def reverse(self, lookup_view, *args, **kwargs):
+    def reverse(self, lookup_view, *args, **kwargs):    
+        prefix = kwargs.pop('__DJANGO_REVERSE_PREFIX','')
         if args and kwargs:
             raise ValueError("Don't mix *args and **kwargs in call to reverse()!")
         try:
@@ -310,19 +311,20 @@ class RegexURLResolver(object):
         except (ImportError, AttributeError), e:
             raise NoReverseMatch("Error importing '%s': %s." % (lookup_view, e))
         possibilities = self.reverse_dict.getlist(lookup_view)
+        prefix_norm, prefix_args = normalize(prefix)[0]
         for possibility, pattern in possibilities:
             for result, params in possibility:
                 if args:
-                    if len(args) != len(params):
+                    if len(args) != len(params) + len(prefix_args):
                         continue
                     unicode_args = [force_unicode(val) for val in args]
-                    candidate =  result % dict(zip(params, unicode_args))
+                    candidate =  (prefix_norm + result) % dict(zip(params, unicode_args))
                 else:
-                    if set(kwargs.keys()) != set(params):
+                    if set(kwargs.keys()) != (set(params)|set(prefix_args)):
                         continue
                     unicode_kwargs = dict([(k, force_unicode(v)) for (k, v) in kwargs.items()])
-                    candidate = result % unicode_kwargs
-                if re.search(u'^%s' % pattern, candidate, re.UNICODE):
+                    candidate = (prefix_norm + result) % unicode_kwargs
+                if re.search(u'^%s%s' % (prefix, pattern), candidate, re.UNICODE):
                     return candidate
         # lookup_view can be URL label, or dotted path, or callable, Any of
         # these can be passed in at the top, but callables are not friendly in
@@ -386,9 +388,8 @@ def reverse(viewname, urlconf=None, args=None, kwargs=None, prefix=None, current
                     raise NoReverseMatch("%s is not a registered namespace inside '%s'" % (key, ':'.join(resolved_path)))
                 else:
                     raise NoReverseMatch("%s is not a registered namespace" % key)
-
-    return iri_to_uri(u'%s%s' % (prefix, resolver.reverse(view,
-            *args, **kwargs)))
+    kwargs['__DJANGO_REVERSE_PREFIX'] = prefix
+    return iri_to_uri(resolver.reverse(view, *args, **kwargs))
 
 reverse_lazy = lazy(reverse, str)
 
diff --git a/tests/regressiontests/urlpatterns_reverse/namespace_urls.py b/tests/regressiontests/urlpatterns_reverse/namespace_urls.py
index 3d34049..0544e75 100644
--- a/tests/regressiontests/urlpatterns_reverse/namespace_urls.py
+++ b/tests/regressiontests/urlpatterns_reverse/namespace_urls.py
@@ -37,11 +37,12 @@ urlpatterns = patterns('regressiontests.urlpatterns_reverse.views',
     (r'^default/', include(default_testobj.urls)),
 
     (r'^other1/', include(otherobj1.urls)),
-    (r'^other2/', include(otherobj2.urls)),
+    (r'^other[246]/', include(otherobj2.urls)),
 
-    (r'^ns-included1/', include('regressiontests.urlpatterns_reverse.included_namespace_urls', namespace='inc-ns1')),
+    (r'^ns-included[135]/', include('regressiontests.urlpatterns_reverse.included_namespace_urls', namespace='inc-ns1')),
     (r'^ns-included2/', include('regressiontests.urlpatterns_reverse.included_namespace_urls', namespace='inc-ns2')),
 
     (r'^included/', include('regressiontests.urlpatterns_reverse.included_namespace_urls')),
+    (r'^inc(?P<outer>\d+)/', include('regressiontests.urlpatterns_reverse.included_urls', namespace='inc-ns5')),
 
 )
diff --git a/tests/regressiontests/urlpatterns_reverse/tests.py b/tests/regressiontests/urlpatterns_reverse/tests.py
index 4f391d9..71e1913 100644
--- a/tests/regressiontests/urlpatterns_reverse/tests.py
+++ b/tests/regressiontests/urlpatterns_reverse/tests.py
@@ -49,6 +49,11 @@ resolve_test_data = (
     # Nested namespaces
     ('/ns-included1/test3/inner/42/37/', 'urlobject-view', 'testapp', 'inc-ns1:test-ns3', 'empty_view', tuple(), {'arg1': '42', 'arg2': '37'}),
     ('/ns-included1/ns-included4/ns-included2/test3/inner/42/37/', 'urlobject-view', 'testapp', 'inc-ns1:inc-ns4:inc-ns2:test-ns3', 'empty_view', tuple(), {'arg1': '42', 'arg2': '37'}),
+
+    # Namespaces capturing variables
+    ('/inc70/', 'inner-nothing', None, 'inc-ns5', views.empty_view, tuple(), {'outer': '70'}),
+    ('/inc78/extra/foobar/', 'inner-extra', None, 'inc-ns5', views.empty_view, tuple(), {'outer':'78', 'extra':'foobar'}),
+    
 )
 
 test_data = (
@@ -335,6 +340,10 @@ class NamespaceTests(TestCase):
         self.assertEqual('/ns-included1/ns-included4/ns-included1/test3/inner/37/42/', reverse('inc-ns1:inc-ns4:inc-ns1:test-ns3:urlobject-view', args=[37,42]))
         self.assertEqual('/ns-included1/ns-included4/ns-included1/test3/inner/42/37/', reverse('inc-ns1:inc-ns4:inc-ns1:test-ns3:urlobject-view', kwargs={'arg1':42, 'arg2':37}))
 
+    def test_nested_namespace_with_variable(self):
+        self.assertEqual('/inc54/', reverse('inc-ns5:inner-nothing', kwargs={'outer':'54'}))
+        self.assertEqual('/inc78/extra/foobar/', reverse('inc-ns5:inner-extra', kwargs={'outer':'78', 'extra':'foobar'}))
+
     def test_app_lookup_object(self):
         "A default application namespace can be used for lookup"
         self.assertEqual('/default/inner/', reverse('testapp:urlobject-view'))
