0

I want to omit the beginning of words starting with some (e.g. something changed to thing).

This is the way I am doing it

(insert (replace-regexp-in-string "\\<\\(some\\)" "" word))

Is this the way to do this? Can it be simplified? do I require to have \\( and \\)?

5
  • If word is somehow obtained from the current buffer, then getting it (however you get it), doing the replacement in the string and then inserting the resulting string is much slower than doing replace-regexp in the buffer directly. I did a simple test with two functions: one that did a replace-regexp on the whole buffer and one that got each word, and did the insert/replace-regexp-in-string you show above. I then ran the two functions on a file that contained 1000 somethings: the whole-buffer fimplementation was almost 100 times faster (4 msec vs 370 msec).
    – NickD
    Aug 13, 2022 at 3:19
  • 4
    Does this answer your question? Omit the beginning of words
    – phils
    Aug 13, 2022 at 4:11
  • Thanks for the elaboration on performance. I do not envisage that doing so on the whole buffer would be frequently preferable. But would be useful if it used a selected region.
    – Dilna
    Aug 13, 2022 at 14:38
  • replace-regexp can be limited to a region.
    – NickD
    Aug 13, 2022 at 15:22
  • Shall look at an implementation with replace-regexp.
    – Dilna
    Aug 13, 2022 at 16:25

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Browse other questions tagged or ask your own question.