All matches of regex in Haskell

后端 未结 1 1189
生来不讨喜
生来不讨喜 2020-12-30 22:36

According to a number of tutorials (including Real World Haskell) one can, using ghci do the following

ghci > :m Text.Regex.Posix
ghci > \"foo foo foo\         


        
相关标签:
1条回答
  • 2020-12-30 23:25

    The regex libraries can be somewhat confusing with their overloaded return types, but to get all the matches you just need to ensure that the return type is AllTextMatches, for example:

    Prelude> :m + Text.Regex.Posix
    Prelude Text.Regex.Posix> getAllTextMatches $ "foo foo foo" =~ "foo" :: [String]
    ["foo","foo","foo"]
    
    0 讨论(0)
提交回复
热议问题