0

I want to replace a list in the form of

1)
2)
3)
4)

with

* 
*
* 

I've tried using the regex [0-9]*\), but it gives Invalid regexp: "Unmatched ) or \\)" and [0-9]*\\) replaces 0 matches. in regex-builder, [0-9]*\) matches the expected items.

I'm using spacemacs 0.300.0 on emacs 26.3

1
  • In Emacs, the meaning of parentheses are inverse, compared to many other regexp systems. ( match a parenthesis whereas \( start a regexp group. (When written as a string, the latter is written "\\(".) Nov 29, 2021 at 19:08

1 Answer 1

1

On writing this question, I found the (very simple) answer, so I'll put it out there for anyone else who finds this confusing (considering I found no similar questions).

It seems that the default behaviour for replace-regexp is matching parenthesis literally, so the solution was just [0-9]*) and for the usual group capturing is instead \(group\), maybe some configuration or variable changes this.

TL;DR: use ) with replace-regexp for literal matches

3
  • 1
    I imagine you want [0-9]+, not [0-9]*.
    – Drew
    Jul 2, 2021 at 19:15
  • There's no configuration or variable to change this. Emacs regexps are just nearer to BRE than ERE when it comes to basic syntax.
    – phils
    Nov 29, 2021 at 21:03
  • There is also rx however, which is a way of expressing Emacs regexps as structured expressions; and for regexp-builder emacs.stackexchange.com/questions/5568 might be helpful.
    – phils
    Nov 29, 2021 at 21:16

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.