-- | A module that exports a simple regex interface. This code is mostly copied-- from the regex-compat package at hackage. I decided to write this module-- because I want to abstract the regex package used.moduleText.Hakyll.Regex(splitRegex,substituteRegex,matchesRegex)whereimportText.Regex.TDFA-- | Match a regular expression against a string, returning more information-- about the match.matchRegexAll::Regex->String->Maybe(String,String,String,[String])matchRegexAll=matchM-- | Replaces every occurance of the given regexp with the replacement string.subRegex::Regex-- ^ Search pattern->String-- ^ Input string->String-- ^ Replacement text->String-- ^ Output stringsubRegex_""_=""subRegexregexpinpreplacement=let-- bre matches a backslash then capture either a backslash or some digitsbre=makeRegex"\\\\(\\\\|[0-9]+)"lookup'_[]_=[]lookup'[]__=[]lookup'match'replgroups=casematchRegexAllbrereplofNothing->replJust(lead,_,trail,bgroups)->letnewval=ifheadbgroups=="\\"then"\\"elseletindex::Intindex=read(headbgroups)-1inifindex==-1thenmatch'elsegroups!!indexinlead++newval++lookup'match'trailgroupsincasematchRegexAllregexpinpofNothing->inpJust(lead,match',trail,groups)->lead++lookup'match'replacementgroups++subRegexregexptrailreplacement-- | Splits a string based on a regular expression. The regular expression-- should identify one delimiter.splitRegex'::Regex->String->[String]splitRegex'_[]=[]splitRegex'delimstrIn=loopstrInwhereloopstr=casematchOnceTextdelimstrofNothing->[str]Just(firstline,_,remainder)->ifnullremainderthen[firstline,""]elsefirstline:loopremainder-- | Split a list at a certain element.splitRegex::String->String->[String]splitRegexpattern=filter(not.null).splitRegex'(makeRegexpattern)-- | Substitute a regex. Simplified interface. This function performs a global-- substitution.substituteRegex::String-- ^ Pattern to replace (regex).->String-- ^ Replacement string.->String-- ^ Input string.->String-- ^ Result.substituteRegexpatternreplacementstring=subRegex(makeRegexpattern)stringreplacement-- | Simple regex matching.matchesRegex::String-- ^ Input string.->String-- ^ Pattern to match.->BoolmatchesRegex=(=~)