@@ -35,6 +35,7 @@ module Hakyll.Core.Identifier.Pattern
36 , parseGlob
36 , parseGlob
37 , predicate
37 , predicate
39 , filterMatches
40 , filterMatches
@@ -46,10 +47,11 @@ module Hakyll.Core.Identifier.Pattern
46import Data.List (isPrefixOf, inits, tails)
47import Data.List (isPrefixOf, inits, tails)
47import Control.Arrow ((&&&), (>>>))
48import Control.Arrow ((&&&), (>>>))
48import Control.Monad (msum)
49import Control.Monad (msum)
49−import Data.Maybe (isJust)
50+import Data.Maybe (isJust, fromMaybe)
50import Data.Monoid (Monoid, mempty, mappend)
51import Data.Monoid (Monoid, mempty, mappend)
52import GHC.Exts (IsString, fromString)
53import GHC.Exts (IsString, fromString)
54+import Text.Regex.PCRE ((=~~))
54import Hakyll.Core.Identifier
56import Hakyll.Core.Identifier
@@ -96,6 +98,15 @@ parseGlob = Glob . parse'
96predicate :: (Identifier -> Bool) -> Pattern
98predicate :: (Identifier -> Bool) -> Pattern
97predicate = Predicate
99predicate = Predicate
101+-- | Create a 'Pattern' from a regex
105+-- > regex "^foo/[^x]*$
107+regex :: String -> Pattern
108+regex str = predicate $ fromMaybe False . (=~~ str) . toFilePath
99-- | Check if an identifier matches a pattern
110-- | Check if an identifier matches a pattern
101matches :: Pattern -> Identifier -> Bool
112matches :: Pattern -> Identifier -> Bool