I came across this issue sometime last year, got the solution from the resident Emacs wizard and forgot about it. Last week, it happened again. I’m recording it now so I don’t forget about it.
Emacs lets you search and replace in a buffer with regular expressions. So far so cool. I needed to replace a part of a lot of HTML links in a file.
<a href="/path/to/file" title="some title">Go!</a>
was to become
<a href="/path/to/file" title="other title">Go!</a>
with varying values for the title attribute obviously. So I searched for
<a href="/path/to/file" title="([^\"]*)">Go!</a>
and Emacs complained about some invalid regex. Darn. I double and triple checked all necessary escape sequences (which I omitted here for clarity) and finally asked the wizard.
Easy, Emacs doesn’t konw the * quantifier. Do this: ‹([^"][^"]+)›
Ah, cheers, that works. But DUH?!
I’m not sure what you mean by emacs not knowing the * quantifier.
The following should have worked (I omit less than and greater than characters for ease of writing) \ a href="/path/to/file" title="([^"]*)">Go!
Looks like my escape sequences on the parens got lost. Obviously those are preceeded with an escape slash.
Emacs 22 even knows:
Right Aaron and that’s what I typically use in those scenarios. I use Emacs 22, but I’m pretty sure that’s not a new addition.
This is Emacs 21 we run there and I do have to look up the exact thing I did, my simple example here doesn’t cut it unfortunately.
Thanks Ben and Aaron for chirping in.
>I’m not sure what you mean by emacs not knowing the * quantifier.
@Ben This is what I got told :-)