The first in a series of exercises designed to teach you more about regular expressions, written by a guy who got partway through writing a regex book.
But first, a word about tools. It's a lot easier to use a tool to do this sort of thing than it is to write code to do it. So, I suggest one of the following:
- The Regulator. No fair to use the library if you choose this tool. Uses a bit of code I wrote to analyze regex for you.
- Regular Expression Workbench (classic) . I wrote this
- Regular Expression Workbench (updated). Version with a different UI on it.
So, S stands for simple, 1 stands for 1, so this first one is going to be pretty simple.
S1 - Match a Social Security Number
Verify that a string is a social security number of the format ddd-dd-dddd.
Answer and explanation to follow.