I am looking for a Haskell function that returns capture groups for all matches of a given regular expression.
I watched Text.Regex but could not find anything.
Now I am using this workaround, which seems to work:
import Text.Regex findNext :: String -> Maybe (String, String, String, [String] ) -> [ [String] ] findNext pattern Nothing = [] findNext pattern (Just (_, _, rest, matches) ) = case matches of [] -> (findNext pattern res) _ -> [matches] ++ (findNext pattern res) where res = matchRegexAll (mkRegex pattern) rest findAll :: String -> String -> [ [String] ] findAll pattern str = findNext pattern (Just ("", "", str, [] ) )
Result:
findAll "x(.)x(.)" "aaaxAxaaaxBxaaaxCx" [["A","a"],["B","a"]]
Question:
- Did I miss something in Text.Regex?
- Is there a Haskell regex library that implements the findAll function?
source share