0

I want to omit the beginning of words starting with some (i.e. something is changed to thing) using the expression

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

But I am getting a lisp error on my regex.

Debugger entered--Lisp error: (invalid-regexp "Trailing backslash")
  string-match("\\<\\some\\" #("something" 0 9 (fontified t)) 0)
  replace-regexp-in-string("\\<\\some\\" "" #("something" 0 9 (fontified t)))
  (insert (replace-regexp-in-string "\\<\\some\\" "" word))
2
  • 2
    What is the question? Aug 12 at 21:42
  • What is the way to remove some from the beginning of a word, with (replace-regexp-in-string "\\<\\(some\\)" "" word)?
    – Ephram
    Aug 12 at 22:47

1 Answer 1

3

Are you looking for this?

(replace-regexp-in-string "\\<\\(some\\)." "" "something" nil nil 1) ; => "thing"

Some unsolicited advice:

You really should try harder to make your questions clearer. For example, your question (apparently) has nothing to do with inserting or insert. You should remove that part from the question, as it's only noise. Take that out of the equation.

Learn to read the error message and backtrace clearly. It says that the error occurred when string-match was called by replace-regexp-in-string.

Read the doc for replace-regexp-in-string and the Elisp manual about regexps. You must have read the manual a bit, or learned elsewhere (1) that \< matches the start of a word and (2) you need to double a backslash in a Lisp string.

But you haven't learned about matching a subexpression (a regexp group). Read the doc string of replace-regexp-in-string and study the expression in this answer - see why I created a group and referenced it with argument 1 in the replace-regexp-in-string call.

It's clear that you're trying, and learning. But you have trouble expressing your questions clearly. Trying to do that better will, in itself, help you learn. And it will get you more help from others. No one wants to guess what you're really asking or play a 20-questions game to find out. It's up to you to express yourself clearly.

2
  • 1
    Agreed. Personally I have been ignoring your questions (I essentially answered emacs.stackexchange.com/q/73041 by accident) because it had become rapidly apparent (at least to my mind) that you are throwing almost every single obstacle you encounter to this site and waiting for someone to solve your problems for you (while often requiring them to guess what your problem actually is), rather than attempting to figure things out for yourself. I believe that if you put more effort into learning and understanding, you would find yourself having fewer problems.
    – phils
    Aug 13 at 4:23
  • Not to solve my problems, but to learn from them. Actual elisp implementations often get too complicated to comprehend for those delving beyond relatively simple customisations.
    – Ephram
    Aug 13 at 14:43

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.