用Haskell正则表达式库替换/替换 [英] replacement / substition with Haskell regex libraries
本文介绍了用Haskell正则表达式库替换/替换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在Haskell中是否存在用于使用正则表达式进行搜索和替换的高级API?特别是,我正在查看 Text.Regex.TDFA
或 Text.Regex.Posix
包.我真的很想要某种类型的东西:
Is there a high-level API for doing search-and-replace with regexes in Haskell? In particular, I'm looking at the Text.Regex.TDFA
or Text.Regex.Posix
packages. I'd really like something of type:
f :: Regex -> (ResultInfo -> m String) -> String -> m String
例如,用"cat"代替"dog"就可以写
so, for example, to replace "dog" with "cat" you could write
runIdentity . f "dog" (return . const "cat") -- :: String -> String
或对单子进行更高级的操作,例如计算出现次数等.
or do more advanced things with the monad, like counting occurrences, etc.
非常缺少有关Haskell的文档.此处.
Haskell documentation for this is pretty lacking. Some low-level API notes are here.