diff --git a/Text/Regex/PCRE/ByteString/Utils.hs b/Text/Regex/PCRE/ByteString/Utils.hs
--- a/Text/Regex/PCRE/ByteString/Utils.hs
+++ b/Text/Regex/PCRE/ByteString/Utils.hs
@@ -51,18 +51,22 @@
                              Right y -> return y
                              Left rr -> throwError (rr ++ " when parsing the replacement string")
     (matches, captures) <- getMatches regexp srcstring V.empty
-    let !replaceString = applyCaptures parsedReplacement captures
+    let !replaceString = applyCaptures firstMatch parsedReplacement captures
         applyReplacement :: RegexpSplit BS.ByteString -> BS.ByteString
         applyReplacement (Unmatched x) = x
         applyReplacement (Matched _) = replaceString
+        firstMatch = case filter isMatched matches of
+                         (Matched x:_) -> x
+                         _     -> ""
     return $! BS.concat $! map applyReplacement matches
 
 -- Transforms the parsed replacement and the vector of captured stuff into
 -- the destination ByteString.
-applyCaptures :: [Replacement] -> V.Vector BS.ByteString -> BS.ByteString
-applyCaptures repl capt = BS.concat (map applyCaptures' repl)
+applyCaptures :: BS.ByteString -> [Replacement] -> V.Vector BS.ByteString -> BS.ByteString
+applyCaptures firstmatch repl capt = BS.concat (map applyCaptures' repl)
     where
         applyCaptures' :: Replacement -> BS.ByteString
+        applyCaptures' WholeMatch = firstmatch
         applyCaptures' (RawReplacement r) = r
         applyCaptures' (IndexedReplacement idx) = if V.length capt < idx
                                                       then ""
@@ -128,6 +132,7 @@
 
 data Replacement = RawReplacement BS.ByteString
                  | IndexedReplacement Int
+                 | WholeMatch
                  deriving (Show)
 
 repparser :: Parser [Replacement]
@@ -146,7 +151,9 @@
             n <- anyChar
             r <- rawData
             return $ BS.cons n r
-    fmap (IndexedReplacement . digitToInt) digit <|> fmap (RawReplacement . BS.cons '\\') ac
+        toReplacement 0 = WholeMatch
+        toReplacement n = IndexedReplacement n
+    fmap (toReplacement . digitToInt) digit <|> fmap (RawReplacement . BS.cons '\\') ac
 
 -- | Compiles the regular expression (using default options) and `substitute`s
 substituteCompile :: BS.ByteString     -- ^ The regular expression
diff --git a/pcre-utils.cabal b/pcre-utils.cabal
--- a/pcre-utils.cabal
+++ b/pcre-utils.cabal
@@ -2,7 +2,7 @@
 -- documentation, see http://haskell.org/cabal/users-guide/
 
 name:                pcre-utils
-version:             0.1.3
+version:             0.1.4
 synopsis:            Perl-like substitute and split for PCRE regexps.
 description:         This package introduces split and replace like functions using PCRE regexps.
 license:             BSD3
diff --git a/test/subs.hs b/test/subs.hs
--- a/test/subs.hs
+++ b/test/subs.hs
@@ -9,6 +9,7 @@
 tests = [ ("l", "x", "lap\\nin", "xap\\nin")
         , ("log(\\d+)truc", "x\\1x", "log186truc", "x186x")
         , ("'", "'\\''", "# This file is managed by Puppet. DO NOT EDIT.", "# This file is managed by Puppet. DO NOT EDIT.")
+        , ("test", "x\\0x", "long test replacement but test", "long xtestx replacement but xtestx")
         ]
 
 toTest :: (BS.ByteString, BS.ByteString, BS.ByteString, BS.ByteString) -> IO Test
