Sara
Sara

Reputation: 189

Using replace-regexp with lisp expression

I have this line:

;Last updated: Sunday, January 23, 2011

I would like to replace the date with the current time. So, I used replace-regxp with the following key combinations:

M-x replace-regexp RET \(Last updated: \)[A-Z ,]*[0-9 ,]* RET \1\,(format-time-string "%A, %B %e, %Y")

But this yields the following result:

;Last updated: Tuesday, January 25, 2011unday, January 23, 2011

How can I get replace-regexp to replace the whole of the old date instead of just the first letter?

Upvotes: 0

Views: 164

Answers (2)

Tyler
Tyler

Reputation: 10032

You're asking for only capital letters.

Try this:

M-x replace-regexp RET \(Last updated: \)[a-zA-Z ,]*[0-9 ,]* RET \1\,(format-time-string "%A, %B %e, %Y")

Upvotes: 0

sepp2k
sepp2k

Reputation: 370192

Your regex only matches upper case letters. Since the u in Sunday is lower case, it only matches Last updated: S, so that's all that gets replaces.

To fix this add a-z to the character range.

Upvotes: 2

Related Questions