加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

所有匹配的正则表达式在Haskell

发布时间:2020-12-14 06:35:01 所属栏目:百科 来源:网络整理
导读:根据许多教程(包括Real World Haskell),可以使用ghci进行以下操作 ghci :m Text.Regex.Posixghci "foo foo foo" =~ "foo" :: [String]["foo","foo","foo"] 然而,当我尝试这个,它产生 No instance for (RegexContext Regex [Char] [String]) arising from
根据许多教程(包括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"]

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读