简体   繁体   中英

Haskell and Regex - Why doesn't my function eliminateRedundantSpaces work?

Haskell and Regex - Why doesn't my function eliminateRedundantSpaces work?

import Text.Regex
eliminateRedundantSpaces text =
 subRegex (mkRegex "\\s+") text " "

Text.Regex uses Posix regular expressions , and that doesn't have the \\s abbreviation defined (that is a perl extension that many other implementations have adopted). Instead you can use the [:space:] character group, eg:

eliminateRedundantSpaces text =
   subRegex (mkRegex "[[:space:]]+") text " "

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM