diff --git a/changelog.md b/changelog.md
--- a/changelog.md
+++ b/changelog.md
@@ -1,5 +1,15 @@
 # Revision history for skylighting and skylighting-core
 
+## 0.10.5.1
+
+  * Regex: Allow lookaheads to capture groups.  Previously
+    captures in lookaheads, like `(?=(a*))`, were ignored.  This
+    led to errors highlighting xml and probably other formats (#121).
+
+  * Throw an exception if a capture group isn't defined (with 'dynamic')
+    rather than simply having getCapture fail so that the rule fails.
+    This will make it easier to debug issues like #121.
+
 ## 0.10.5
 
   * Fix regression from 0.10.3 with Haskell highlighting of Char (#120).
diff --git a/skylighting-core.cabal b/skylighting-core.cabal
--- a/skylighting-core.cabal
+++ b/skylighting-core.cabal
@@ -1,5 +1,5 @@
 name:                skylighting-core
-version:             0.10.5
+version:             0.10.5.1
 synopsis:            syntax highlighting library
 description:         Skylighting is a syntax highlighting library.
                      It derives its tokenizers from XML syntax
@@ -59,6 +59,7 @@
                      test/cases/life.lua
                      test/cases/hk91.html
                      test/cases/if.cmake
+                     test/cases/docbook.xml
                      test/cases/issue41.djangotemplate
                      test/expected/abc.ada.native
                      test/expected/abc.agda.native
@@ -91,6 +92,7 @@
                      test/expected/hk91.html.native
                      test/expected/if.cmake.native
                      test/expected/issue41.djangotemplate.native
+                     test/expected/docbook.xml.native
 
 cabal-version:       >=1.10
 
@@ -130,7 +132,7 @@
                        safe,
                        base64-bytestring,
                        blaze-html >= 0.5,
-                       containers >= 0.5.8.2,
+                       containers >= 0.6.0.1,
                        ansi-terminal >= 0.7,
                        colour >= 2.0
   hs-source-dirs:      src
diff --git a/src/Regex/KDE/Match.hs b/src/Regex/KDE/Match.hs
--- a/src/Regex/KDE/Match.hs
+++ b/src/Regex/KDE/Match.hs
@@ -65,7 +65,11 @@
 exec _ _ AssertEnd = Set.filter (\m -> matchOffset m == B.length (matchBytes m))
 exec _ _ AssertBeginning = Set.filter (\m -> matchOffset m == 0)
 exec top _ (AssertPositive dir regex) =
-  Set.filter (\m -> not (null (exec top dir regex (Set.singleton m))))
+  Set.unions . Set.map
+    (\m -> Set.map (\m' -> -- we keep captures but not matches
+                            m'{ matchBytes = matchBytes m,
+                               matchOffset = matchOffset m })
+           $ exec top dir regex (Set.singleton m))
 exec top _ (AssertNegative dir regex) =
   Set.filter (\m -> null (exec top dir regex (Set.singleton m)))
 exec _ _ AssertWordBoundary = Set.filter atWordBoundary
diff --git a/src/Skylighting/Tokenizer.hs b/src/Skylighting/Tokenizer.hs
--- a/src/Skylighting/Tokenizer.hs
+++ b/src/Skylighting/Tokenizer.hs
@@ -36,7 +36,6 @@
 import Data.Semigroup
 #endif
 
-
 newtype ContextStack = ContextStack{ unContextStack :: NonEmpty Context }
   deriving (Show)
 
@@ -527,7 +526,7 @@
         Just (matchedBytes, capts) -> do
           unless (null capts) $
              modify $ \st -> st{ captures =
-                                  IntMap.map (toSlice matchedBytes) capts }
+                                  IntMap.map (toSlice inp) capts }
           takeChars (UTF8.length matchedBytes)
         _ -> mzero
 
@@ -575,7 +574,7 @@
 getCapture capnum = do
   capts <- gets captures
   case IntMap.lookup capnum capts of
-     Nothing -> mzero
+     Nothing -> throwError $ "Capture " <> show capnum <> " not defined!"
      Just x  -> decodeBS x
 
 keyword :: KeywordAttr -> WordSet Text -> ByteString -> TokenizerM Text
diff --git a/test/cases/docbook.xml b/test/cases/docbook.xml
new file mode 100644
--- /dev/null
+++ b/test/cases/docbook.xml
@@ -0,0 +1,13 @@
+<?xml version="1.0" encoding="utf-8"?>
+<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook V3.1//EN">
+<article>
+  <!-- just an example -->
+  <sect1>
+    <title>The Month of May</title>
+      <para>
+      When you install DocBook Tools a number of files are added to
+      <filename class="directory">/usr/bin</filename>, including
+      <filename>db2html</filename>, and <filename>db2pdf</filename>.
+      </para>
+  </sect1>
+</article>
diff --git a/test/expected/docbook.xml.native b/test/expected/docbook.xml.native
new file mode 100644
--- /dev/null
+++ b/test/expected/docbook.xml.native
@@ -0,0 +1,69 @@
+[ [ ( FunctionTok , "<?xml" )
+  , ( OtherTok , " version=" )
+  , ( StringTok , "\"1.0\"" )
+  , ( OtherTok , " encoding=" )
+  , ( StringTok , "\"utf-8\"" )
+  , ( FunctionTok , "?>" )
+  ]
+, [ ( DataTypeTok , "<!DOCTYPE" )
+  , ( NormalTok , " " )
+  , ( DataTypeTok , "article" )
+  , ( NormalTok , " PUBLIC \"-//OASIS//DTD DocBook V3.1//EN\"" )
+  , ( DataTypeTok , ">" )
+  ]
+, [ ( NormalTok , "<" )
+  , ( KeywordTok , "article" )
+  , ( NormalTok , ">" )
+  ]
+, [ ( NormalTok , "  " )
+  , ( CommentTok , "<!-- just an example -->" )
+  ]
+, [ ( NormalTok , "  <" )
+  , ( KeywordTok , "sect1" )
+  , ( NormalTok , ">" )
+  ]
+, [ ( NormalTok , "    <" )
+  , ( KeywordTok , "title" )
+  , ( NormalTok , ">The Month of May</" )
+  , ( KeywordTok , "title" )
+  , ( NormalTok , ">" )
+  ]
+, [ ( NormalTok , "      <" )
+  , ( KeywordTok , "para" )
+  , ( NormalTok , ">" )
+  ]
+, [ ( NormalTok
+    , "      When you install DocBook Tools a number of files are added to"
+    )
+  ]
+, [ ( NormalTok , "      <" )
+  , ( KeywordTok , "filename" )
+  , ( OtherTok , " class=" )
+  , ( StringTok , "\"directory\"" )
+  , ( NormalTok , ">/usr/bin</" )
+  , ( KeywordTok , "filename" )
+  , ( NormalTok , ">, including" )
+  ]
+, [ ( NormalTok , "      <" )
+  , ( KeywordTok , "filename" )
+  , ( NormalTok , ">db2html</" )
+  , ( KeywordTok , "filename" )
+  , ( NormalTok , ">, and <" )
+  , ( KeywordTok , "filename" )
+  , ( NormalTok , ">db2pdf</" )
+  , ( KeywordTok , "filename" )
+  , ( NormalTok , ">." )
+  ]
+, [ ( NormalTok , "      </" )
+  , ( KeywordTok , "para" )
+  , ( NormalTok , ">" )
+  ]
+, [ ( NormalTok , "  </" )
+  , ( KeywordTok , "sect1" )
+  , ( NormalTok , ">" )
+  ]
+, [ ( NormalTok , "</" )
+  , ( KeywordTok , "article" )
+  , ( NormalTok , ">" )
+  ]
+]
diff --git a/test/test-skylighting.hs b/test/test-skylighting.hs
--- a/test/test-skylighting.hs
+++ b/test/test-skylighting.hs
@@ -317,6 +317,7 @@
   , ("(?|(abc)|(def))", "abc", Just ("abc", [(1,"abc")]))
   , ("(?|(abc)|(def))", "def", Just ("def", [(1,"def")]))
   , ("(?:(abc)|(def))", "def", Just ("def", [(2,"def")]))
+  , ("d(?=(bc)|(ef))", "def", Just ("d", [(2,"ef")]))
   ]
 
 
