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

Luctins
  • 120
  • 7
  • 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 `"\\("`.) – Lindydancer Nov 29 '21 at 19:08

1 Answers1

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

Luctins
  • 120
  • 7
  • 1
    I imagine you want `[0-9]+`, not `[0-9]*`. – Drew Jul 02 '21 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 '21 at 21:03
  • There is also `rx` however, which is a way of expressing Emacs regexps as structured expressions; and for `regexp-builder` https://emacs.stackexchange.com/questions/5568 might be helpful. – phils Nov 29 '21 at 21:16