Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I can't just delete all of the hyphens, because elsewhere they are used as minus signs. I can find these dates with [0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\} but I can't figure out how to keep those three different digit wildcards in memory. My attempts end up replacing the dates with the search string (e.g., :%s/[0-9]\{4\}-[0-9]\{2\}-[0-9]\{2\}/[0-9]\{4\}[0-9]\{2\}[0-9]\{2\}/g).

Any ideas? If there's a command line solution, I'd love to learn that, too. Thanks!

share|improve this question
up vote 3 down vote accepted

You just need to use capture groups:


The parentheses capture the matches within, then the backreferences output those capture groups. Since the hyphens are outside the groups, they're excluded.

share|improve this answer
You can also simplify [0-9] with \d – Luc Hermitte Feb 14 '11 at 12:54

I don't know vim so this is a workaround that you can still perform in vim:

Since you can find the hyphens that occur in dates, replace them with something else (a character or sttring) that you know doesn't occur in the document. Then do a second search/replace to replace your new character/string with nothing, thereby deleting it.

share|improve this answer
but wouldn't that delete the minus signs I need elsewhere? – Richard Herron Feb 13 '11 at 5:03

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.