【发布时间】:2017-08-02 17:45:52
【问题描述】:
我想将这个 SO 问题 Find string between two substrings 中的 python 正则表达式 (PCRE) 技术改编为 Haskell,以便我可以在 Haskell 中做同样的事情。
但我不知道如何使它在 GHC (8.2.1) 中工作。我已经安装了cabal install regex-pcre,经过一番搜索,得到了以下测试代码:
import Text.Regex.PCRE
s = "+++asdf=5;iwantthis123jasd---"
result = (s ++ s) =~ "asdf=5;(.*)123jasd" :: [[String]]
我希望得到中间字符串的第一个和最后一个实例
iwantthis
但我无法得到正确的结果:
[["asdf=5;iwantthis123jasd---+++asdf=5;iwantthis123jasd","iwantthis123jasd---+++asdf=5;iwantthis"]]
我以前没有在 Haskell 中使用过 regex 或 pcre。
有人可以帮助正确使用(提取第一次和最后一次出现)吗?
另外,我不太了解这里的::[[String]] 用法。它有什么作用,为什么需要它?
我搜索了documentation,但没有发现将类型转换为:: [[String]] 的用法。
【问题讨论】: