@@ -35,6 +35,7 @@ module Hakyll.Core.Identifier.Pattern
3535 ( Pattern
3636 , parseGlob
3737 , predicate
38+ , regex
3839 , matches
3940 , filterMatches
4041 , capture
@@ -46,10 +47,11 @@ module Hakyll.Core.Identifier.Pattern
4647import Data.List (isPrefixOf, inits, tails)
4748import Control.Arrow ((&&&), (>>>))
4849import Control.Monad (msum)
49−import Data.Maybe (isJust)
50+import Data.Maybe (isJust, fromMaybe)
5051import Data.Monoid (Monoid, mempty, mappend)
5152
5253import GHC.Exts (IsString, fromString)
54+import Text.Regex.PCRE ((=~~))
5355
5456import Hakyll.Core.Identifier
5557
@@ -96,6 +98,15 @@ parseGlob = Glob . parse'
9698predicate :: (Identifier -> Bool) -> Pattern
9799predicate = Predicate
98100
101+-- | Create a 'Pattern' from a regex
102+--
103+-- Example:
104+--
105+-- > regex "^foo/[^x]*$
106+--
107+regex :: String -> Pattern
108+regex str = predicate $ fromMaybe False . (=~~ str) . toFilePath
109+
99110-- | Check if an identifier matches a pattern
100111--
101112matches :: Pattern -> Identifier -> Bool