Haskell和Regex - 为什么我的函数不能消除RedundantSpaces的工作?
import Text.Regex
eliminateRedundantSpaces text =
subRegex (mkRegex "\\s+") text " "
Run Code Online (Sandbox Code Playgroud)
Dav*_*ani 10
Text.Regex使用Posix正则表达式,并且没有\s定义缩写(这是许多其他实现已采用的perl扩展).相反,您可以使用[:space:]字符组,例如:
eliminateRedundantSpaces text =
subRegex (mkRegex "[[:space:]]+") text " "
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
127 次 |
| 最近记录: |