I have a string "\\303\\273" that I want to decode into û.

It's known that (decode-coding-string "\303\273" 'utf-8) evals to û.

However, I'm not able to translate "\\303\\273" into "\303\273" with replace-regexp-in-string.

Question: How to decode "\\303\\273" into û?


"\303\273" is 2 bytes and "\\303\\273" is 8 bytes, the problem with replace-regexp-in-string is it eagerly converts \303 to à and \273 to ».

 (rx "\\" (group (1+ (in "0-7"))))
 (lambda (s)
     (match-string 1 s)
;; => "û"

Here is a way without replace-regexp-in-string. Note that you need unibyte-string not string, since string will have the same problem as replace-regexp-in-string.

  #'unibyte-string ;; string does not work
   (lambda (s)
      (substring s 1)
   (seq-partition "\\303\\273" 4)))
;; => "û"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.