This is a problem with Mac / OSX!
I have the following string with a length of three characters:
"a\160b"
I want to combine and replace the middle character
Several approaches, such as
ghci> :m +Text.Regex ghci> subRegex (mkRegex "\160") "a\160b" "X" "*** Exception: user error (Text.Regex.Posix.String died: (ReturnCode 17,"illegal byte sequence")) ghci> subRegex (mkRegex "\\160") "a\160b" "X" "a\160b"
did not give the desired result.
How do I change the regexp variable or my environment to replace "\ 160" with "X"?
The problem seems to have a root in the input locale / encoding.
bash> locale LANG= LC_COLLATE="C" LC_CTYPE="UTF-8" LC_MESSAGES="C" LC_MONETARY="C" LC_NUMERIC="C" LC_TIME="C" LC_ALL=
I have already changed my .bashrc to export the following env-vars:
bash> locale LANG="en_US.UTF-8" LC_COLLATE="en_US.UTF-8" LC_CTYPE="en_US.UTF-8" LC_MESSAGES="en_US.UTF-8" LC_MONETARY="en_US.UTF-8" LC_NUMERIC="en_US.UTF-8" LC_TIME="en_US.UTF-8" LC_ALL="en_US.UTF-8"
But that didn't change the behavior at all.
regex unicode haskell macos
Axel tetzlaff
source share