根据许多教程(包括Real World Haskell),可以使用ghci进行以下操作
ghci > :m Text.Regex.Posix ghci > "foo foo foo" =~ "foo" :: [String] ["foo","foo","foo"]
然而,当我尝试这个,它产生
No instance for (RegexContext Regex [Char] [String]) arising from a use of `=~' Possible fix: add an instance declaration for (RegexContext Regex [Char] [String]) In the expression: "abc" =~ "ab" :: [String] In an equation for `it': it = "abc" =~ "ab" :: [String]
获得一个在哈克的所有比赛的列表的正确方法是什么?
正则表达式库可能与他们的重载返回类型有点混乱,但要获得所需的所有匹配,以确保返回类型为AllTextMatches,例如:
Prelude> :m + Text.Regex.Posix Prelude Text.Regex.Posix> getAllTextMatches $ "foo foo foo" =~ "foo" :: [String] ["foo","foo"]