;dev: add Utils.Regex.regexMatchTextGroups
A matcher function which returns the list of match-groups, which may be empty. Signed-off-by: Jonathan Dowland <jon@dow.land>
This commit is contained in:
parent
c619e387ea
commit
549c47bca8
@ -55,6 +55,7 @@ module Hledger.Utils.Regex (
|
|||||||
-- * total regex operations
|
-- * total regex operations
|
||||||
,regexMatch
|
,regexMatch
|
||||||
,regexMatchText
|
,regexMatchText
|
||||||
|
,regexMatchTextGroups
|
||||||
,regexReplace
|
,regexReplace
|
||||||
,regexReplaceUnmemo
|
,regexReplaceUnmemo
|
||||||
,regexReplaceAllBy
|
,regexReplaceAllBy
|
||||||
@ -72,7 +73,8 @@ import qualified Data.Text as T
|
|||||||
import Text.Regex.TDFA (
|
import Text.Regex.TDFA (
|
||||||
Regex, CompOption(..), defaultCompOpt, defaultExecOpt,
|
Regex, CompOption(..), defaultCompOpt, defaultExecOpt,
|
||||||
makeRegexOptsM, AllMatches(getAllMatches), match, MatchText,
|
makeRegexOptsM, AllMatches(getAllMatches), match, MatchText,
|
||||||
RegexLike(..), RegexMaker(..), RegexOptions(..), RegexContext(..)
|
RegexLike(..), RegexMaker(..), RegexOptions(..), RegexContext(..),
|
||||||
|
(=~)
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@ -166,6 +168,14 @@ regexMatch = matchTest
|
|||||||
regexMatchText :: Regexp -> Text -> Bool
|
regexMatchText :: Regexp -> Text -> Bool
|
||||||
regexMatchText r = matchTest r . T.unpack
|
regexMatchText r = matchTest r . T.unpack
|
||||||
|
|
||||||
|
-- | Return a (possibly empty) list of match groups derived by applying the
|
||||||
|
-- Regex to a Text.
|
||||||
|
regexMatchTextGroups :: Regexp -> Text -> [Text]
|
||||||
|
regexMatchTextGroups r txt = let
|
||||||
|
pat = reString r
|
||||||
|
(_,_,_,matches) = txt =~ pat :: (Text,Text,Text,[Text])
|
||||||
|
in matches
|
||||||
|
|
||||||
--------------------------------------------------------------------------------
|
--------------------------------------------------------------------------------
|
||||||
-- new total functions
|
-- new total functions
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user