I'm trying to find every date and put quotes around it. I thought this should be:
M-x replace-regexp 201\d-\d\d-\d\d  <ret>   '\&'
I also tried [0-9] instead of \d.
it doesn't work.  But using isearch-forward-regexp I can type [0-9][0-9] and watch the targets highlight.  What am I doing wrong with the replace?
Emacs regexps don't have the common \d shorthand for [0-9].
I just put the text 2011-04-01 into a new buffer, went back to the start of the buffer, and typed M-x replace-regexp RET 201[0-9]-[0-9][0-9]-[0-9][0-9] RET '\&' RET, and the date was surrounded by single quotes, as expected.
\d is not supported in Emacs regular expression syntax (C-h S regexp has documentation on them).  You can use [0-9] as you did, or use the POSIX style [[:digit:]].
However, what you did (with [0-9]) should have worked, and did in fact just work for me. If you're using a regular expression in a program you might also find M-x regexp-builder useful.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With