Digital humanities

Maintained by: David J. Birnbaum ( [Creative Commons BY-NC-SA 3.0 Unported License] Last modified: 2017-02-05T17:55:32+0000

Test #3: regex

General directions

If you want to test your regex as you develop, you might find Regexpal helpful.

Your regex expressions in Part 2 should do the following:

Part 1

Explain in prose what the following regular expressions match:

  1. [1-9]\.[A-Za-z]
  2. "(.*?)"
  3. \d{4,}
  4. ^[IVXLC]+$
  5. [A-Z][a-z]{1,2}\.

Part 2

Give a regex you might use to match:

  1. Any standard US social security number, e.g., 212-12-1212
  2. Any standard filename, with a main component that contains just lowercase letters, digits, hyphens, and underscores; a period; and then a three-letter extension, e.g., filename.xml
  3. Any word ending in ier that starts with an upper-case letter and is at least six letters long, e.g., Happier
  4. Any hyphenated word, which may include any number of hyphens, e.g., up-to-date