我想修改这个SO问题Find string between two substrings中的python正则表达式(PCRE)技术到Haskell,这样我就可以在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中使用正则表达式或pcre。
有人可以帮助正确的使用(提取第一次和最后一次出现)? 另外,我不太了解::[[String]]
这里的用法。它做什么,为什么它是必要的?
我搜索了documentation,但未发现类型转换为:: [[String]]
的用法。
'地图(!! 1)'可能更可读,因为数字表示捕获组。 – 4castle