Of Spaces, Underscores and Dashes

I try to avoid using spaces in filenames and URLs. They’re great for human readability, but they’re remarkably inconvenient in computer resource locators:

Any spaces in URLs are converted to the encoded space character by the web browser:

XCOPY "c:\test files\reference data.doc" d:
XCOPY c:\test-files\reference-data.doc d:

A filename with spaces has to be surrounded by quotes when referenced at the command line:

http://domain.com/test%20files/reference%20data.html
http://domain.com/test-files/reference-data.html

So it behooves us to use something other than a space in file and folder names. Historically, I’ve used underscore, but I recently discovered that the correct character to substitute for space is the dash. Why?

The short answer is, that’s what Google expects:

If you use an underscore ‘_’ character, then Google will combine the two words on either side into one word. So bla.com/kw1_kw2.html wouldn’t show up by itself for kw1 or kw2. You’d have to search for kw1_kw2 as a query term to bring up that page.

The slightly longer answer is, the underscore is traditionally considered a word character by the w regex operator.

Here’s RegexBuddy matching the w operator against multiple ASCII character sets:

As you can see, the dash is not matched, but underscore is. This_is_a_single_word, but this-is-multiple-words.

Like NutraSweet and Splenda, neither is really an acceptable substitute for a space, but we might as well follow the established convention instead of inventing our own. That’s how we ended up with the backslash as a path separator.

Jeff Atwood

Written by Jeff Atwood

Indoor enthusiast. Co-founder of Stack Overflow, Discourse, and RGMII. Disclaimer: I have no idea what I'm talking about. Let's be kind to each other. Find me https://infosec.exchange/@codinghorror

⏲️ Busy signing you up.

❗ Something's gone wrong. Please try again.

✅ Success! Check your inbox (and your spam folder, just in case).

Recent Posts

An interactive TWiT Series You're the hero of the story! Choose from 1,024 possible endings. OFF by ONE with Jeff Atwood Hosted by Leo Laporte "every choice changes everything!"

Every Choice Changes Everything: The Show

About 3 weeks ago, Leo Laporte and I recorded the first episode of what will be a new monthly show on the TWiT network. Naming things is hard, and we almost voted on the name, like we did for Stack Overflow, but we quickly landed on Off By One with

By Jeff Atwood ·
Comments
Thank You For Being a Friend

Thank You For Being a Friend

It's been one of those months, and by that, I mean one of the 663 months since I was born. This won't be a long post, because I only have two things to say. First, I'm really glad we re-ordered the GMI (Guaranteed

By Jeff Atwood ·
Comments
map of the United States via rgmii.org showing all 3,143 counties by rural (gold) / metro (grey) and population

Launching The Rural Guaranteed Minimum Income Initiative

It's been a year since I invited Americans to join us in a pledge to Share the American Dream: 1. Support organizations you feel are effectively helping those most in need across America right now. 2. Within the next five years, also contribute public dedications of time or

By Jeff Atwood ·
Comments
I’m feeling unlucky... 🎲   See All Posts