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 combinati开发者_如何学运维ons:
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?
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.
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")
精彩评论