Though most people don’t know (or care when told), the correct character to use for a range of numbers is the en dash (–), not the hyphen (-). Even if you’re committed to using en dashes between digits, hyphens are a tad easier to type,1 making a find and replace necessary at some point. If you’re diligent and use the en dash faithfully, you will undoubtedly get a rogue hyphen in there somewhere if you do any copying and pasting from the internet or other documents that don’t consistently use the correct character.
A simple find and replace (- for –) would do the trick—if you wanted to replace all hyphens with en dashes. But you don’t want to do this, since hyphens in hyphenated words are correct. :) Alternatively, you could run that query but, instead of replacing them all at once, replace one at a time only the ones that appear between digits. But this could be time consuming on a large document like a dissertation. Another option would be to set up a query to find 0-0 and replace it with 0–0, then 0-1 with 0–1 and so forth, but that would require 100 different searches and probably take longer than the previous method! The previous method could probably be simplified by dropping the second digit since there aren’t likely to be any instances when you’d have a digit followed by a hyphen not followed by another digit. That would make only 10 find-and-replace queries. So this is as least doable, though still not ideal.
Fortunately, there is a better solution than any of these.
What we want to do is find any single digit followed by a hyphen followed by another single digit and replace the hyphen with an en dash, leaving the digits unchanged. I tried to use the special digit character, ^#, and came up with a query like find ^#-^# and replace it with ^#–^#, but this didn’t work because ^# is not valid in the replace field.
I knew there had to be a way to do it, but I couldn’t figure it out. So I went to Google and found my answer in just a minute or two.
Here’s what you do:
- In the “Find what” field, enter ([0-9])-([0-9]).
- In the “Replace with” field, enter \1–\2 (note that that’s an en dash, not a hyphen).
- Check the box “Use wildcards.”
- Click “Replace All.”
That’s it. Much easier than any of the other methods. See the article for more details and an explanation of the search syntax.
- To type an en dash in Word, you can either use the default key combination Ctrl + – (the one on the keypad) or create your own shortcut. My shortcut is Ctrl + – (the one on the main part of the keyboard). [↩]
Ryan Burns says
Two things: First, I know that you were thinking of me the entire time you wrote this post, and that I was the reason for the parenthetical remark in the first sentence. Second, I know that you knew I would comment on this post—you were right. However, did you expect that I would pepper my comment with egregious misuses of the dash? I thought not.
Phil Gons says
Well, I have to admit, you did come to mind when I wrote this, but “the entire time” is a bit strong. And, yes, I did have you particularly in mind with the “don’t care” bit. :) However, I didn’t expect you to comment (you read my blog?), and I really didn’t expect you to so horribly abuse the hyphen, en dash, and em dash in your comment.
Hey, I bet you didn’t expect me to edit your comment to clean up those egregious errors, did you? Or maybe you did. You know me too well.
Ryan Burns says
Dang it! You’re good. A little too good.
Lawrence says
Alternatively, to insert an n-dash in almost any program simply hold down the ALT key and type 150 on the numerical keypad (assuming number lock is on, of course). The nice thing about this approach is that you can do it for any ANSI/Unicode character (e.g. ellipsis = 133, m-dash = 151).
Phil Gons says
Lawrence, thanks for the tip, but when I try these I get û, à, and ù respectively. I get this is Firefox, Outlook, Word, etc. I think you mean 0150, 0133, and 0151, which do produce the behavior you’re talking about.
Mark says
For those Linux users out there, there are lots of ways to enter en dashes and em dashes. In some distributions you can hold ctrl and shift and press u while you do that. Then an underlined u will appear. Then type in the Unicode hexadecimal value for whatever Unicode character you want, and it will appear.
An easier and faster way to do common special characters (not every single Unicode character) is to set up your compose key. In Debian and Ubuntu with GTK 2, go to keyboard, layouts, and enable the compose key. In Xfce (or Xubuntu or whatever), you can set up a script and set it to start up with your machine, with this content, which will enable it:
#!/bin/bash
setxkbmap -option compose:lwin
In this case, the left windows key is the compose key. The compose key is easy to use, once set up. To type an em dash, just press the compose key and then the hyphen key three times. To do an a with an accent press compose then apostrophe then a. Anyway, I’m making it sound more complicated than it is, I bet.
Does the same syntax for replacing the en dashes work in OpenOffice (and LibreOffice, which is pretty much the same thing)?
Also, how do you avoid putting en dashes in phone numbers and stuff like that? If you could search to make sure there aren’t more numbers and dashes around, that would be great. Any idea how?
Mark says
Type an en dash with compose hyphen hyphen period.
The Unicode hexadecimal representation of an en dash is 2013 (u+2013).
Anyway, phone numbers require figure dashes (u+2012). I don’t know that most fonts even make them look any different, though. You’d have to check. Figure dashes are supposed to take the same amount of space as a number: 1‒234‒567‒8910
Even less people use figure dashes than en dashes.
Jack Caviness says
Phil
In Word for Mac, (2008 & Word X), this did not work for me. I receive an error message: “The Replace With text contains a group number which is out of range.” This happens no matter how I enter the en dash, and even when I only enter “\1” into the “Replace with” field.
Since I skipped Word 2004, I could not try it there, but I assume it would work like the other two.
Jack
Phil Gons says
Jack, did you try the couple of suggestions in the article?
If these don’t help, I’m not sure what to suggest.
Peter G. says
Phil,
This is good to know. I knew there had to be a way to do this but had never taken the time to find out. In my own papers I have simply been inserting en-dashes manually each time using the same shortcut you mentioned. But putting this search & replace function into a macro will be nice for other people’s documents (e.g. my professors’ syllabi).
Justin Taylor says
Ah…you couldn’t have posted this before we edited the ESV Study Bible?? :)
JT
Phil Gons says
Sorry about that, Justin. :) (Just pulled your comment out of SPAM.)
Phil says
Download and install AllChars, a wonderful applet for the PC that facilitates inserting all the off-keyboard characters.
http://allchars.zwolnet.com/
Phil Gons says
Thanks, Phil. How does AllChars differ from Character Map in Windows or BabelMap?
threegirldad says
On the other hand, you just might end up wishing that you had left well enough alone – such as, for example, after “correcting” an electronic One Year Bible Reading plan only to discover that a certain online Bible site ([cough]ESVSB[cough]) “throws a rod” if an en-dash rather than a hyphen is part of the Search string.
Ahem…
Andrea says
Mr. Gons,
Any shortcuts for a laptop without a number pad? It’s a little tiresome to let auto correct do it by typing “number space hyphen space number space” and delete the spaces. I guess I could just find and replace now though. Thanks.
I’ll add this to “Omega always wins” in my list of things I learned from you.
Your former student,
Andrea Crocker
Phil Gons says
Andrea, nice to hear from you. Please greet your husband for me!
In Word you can set your own shortcut. As I mentioned, I use Ctrl + – (the one next to 0). Alt 0150 has the advantage of working anywhere without needing to create a shortcut. Find and Replace at the end of a large document is a good way to go. For shorter documents, it’s probably not worth it and best to use one of the shortcuts for typing it.
Did I really say that? I hope there is more on your list than this and that statement, or I’d feel like a pretty lousy teacher!
Larry says
If I remember correctly, in Word 2003 (and probably others as well), if you are using a full size keyboard, cntrl the dash (or minus sign) on the number pad does the en dash.
I don’t have my full size keyboard here to try, but if you have one, I am pretty sure this is the combination. It is easier than the alt-150. BTW, alt 151 is the em-dash.
Phil Gons says
As I mentioned in my post, Ctrl + – (the one on the keypad) is the standard MS Office shortcut for the en dash. You can also create your own, which I make Ctrl + – (the one on the main part of the keyboard).
As Lawrence pointed out in his comment and I corrected in mine, Alt 0150 is the key combination for the en dash and Alt 0151 for the em dash.
Phil says
The applet AllChars runs in the background. When you hit the Ctrl key, it awaits two characters and will then turn that into a character. For instance Ctrl-n-hyphen outputs an en dash, and Ctrl-m-hyphen outputs an em dash. Or Ctrl-x-x gives a multiplication sign. It’s pretty cool.
Phil Gons says
Good to know. Thanks, Phil.
Larry says
I missed your footnote there somehow, Phil. My apologies. You had already said what I said.
Phil Gons says
No problem, Larry. Someone else may have as well, so it doesn’t hurt to repeat it. Sorry for my matter-of-fact (i.e., less-than-kind reply). :(
Mark Snoeberger says
Wow, a serious blog exchange about en dashes…with 16 entries, no less! The world is becoming a better place. It must be Obama. I have tears in my eyes.
Seriously, this is a helpful trick, Phil, and I have used it teaching Theological Research Methods here at DBTS. Unfortunately, a few errant hyphens can still get through, such as date ranges that use months (like Bibliotheca Sacra and others) and Roman numerals. For this reason I still recommend that students use the simple find and replace (en dash for hyphen) and choose the one-at-a-time option.
MAS
Phil Gons says
Thanks for the comment, Mark. Good points. I wonder if Word is robust enough to handle a regular expression that could account for months and Romans numerals. There are a number of people at work who are very skilled with regular expressions. I may have to check with one of them to see what that would look like.
Any other exceptions that you can think of?
Michael says
Hmmm… I left a comment on this post the other day and it has magically disappeared.
Phil Gons says
Michael, let me take a look in my SPAM filter to see if it got sent there.
Phil Gons says
Sorry, Michael. Couldn’t find it. I never check through my SPAM. I just get too much. But I just looked through the last several hundred and, while I found four comments from others, I didn’t see yours.
Valentin says
Awesome tip, works in OpenOffice as well (check the option ‘regular expression’).
Justin Taylor says
Phil,
Thanks again for this tip, which is incredibly handy.
One thing to watch for: I think this formula will miss entries like Matt. 1b-2.
Blessings!
JT
Phil Gons says
You could modify the first line to
([0-9a-z])-([0-9])
. This would find any number or lowercase letter followed by a hyphen followed by a number. This might be too sloppy though, but I can’t think of any cases where you’d have a letter followed by a hyphen followed by a number where you wouldn’t want to use this find and replace. Let me know if you can think of one. If you can, it’s possible to tweak it further to require a number followed by a letter followed by a hyphen followed by a number. But I might need to get my wife’s help for that one.Tim Bulkeley says
When I tried this in Open Office what happened was that things like: 1:3-2:16 became monsters like: 1:\1–\2 :16. (Yes I did tick “regular expressions”.)
Chuck says
I had a different but related problem, and this very helpfully solved it. Thank you! Once I got all the details correct, my very large document found and replaced 189 instances in about a second. Bravo!
Rick says
I’m running Word 2003. I have a document of about 200,000 words and have to replace a dash for an en-dash. When I put in cntrl + – in the replace box for Find and Replace, nothing happens, over and over. Auto correct has the box marked for replacing dash for en–dash. Alt 0150 doesn’t help either. There has to be another answer for this because your solution won’t work.
Shruti says
When I tried your solutions, my 2-3 got replaced with 23– :( What went wrong?