I want to replace some digits by letters such that

1 ---> a
2 ---> b

In emacs I have tried the following replacement:

M-x query-replace-regexp RET \([0-9]+\) RET \,(string (+ ?a \#1)) RET

It works, but in replacement I obtain 1 --> b, 2 --> c, and so on. Please, how can I fix it?

PS: I know that with my code 26 --> {, but it is not a problem because my digits are generally less than 26.

  • Does (+ (1- ?a) \#1) work?
    – InHarmsWay
    Mar 14 '19 at 9:20
  • @InHarmsWay Yes, it works! Thanks! Mar 14 '19 at 9:30
  • @InHarmsWay: Please post your comment as an answer. OP: Please accept the answer. Alternatively, if you think your question and the answer aren't helpful for other readers then please consider deleting the question. Thx.
    – Drew
    Mar 14 '19 at 14:29

The following should work:

M-x query-replace-regexp RET \([0-9]+\) RET \,(string (+ (1- ?a) \#1)) RET

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.