Unix Regular Expressions (1/2 day -- 4 hours)

Synopsis This class demystifies regular expressions so that even people without pocket protectors can supercharge their pattern matching and substitution in vi, grep, sed, emacs, awk, Perl, and other text-processing programs and languages. After an overview of what regular expressions can (and cannot) do, students learn the syntax of various programs that use REs. Next the fundamental metacharacters that work in all programs are covered in detail. In the third section, students will learn advanced topics that can be applied to everyday scripting needs. well as edit existing ones.
Target audience This class is for anyone who works with text files - programmers, DBAs, system administrators, and HTML or XML designers.
Prerequisites This class requires an introductory level of familiarity with Unix, including use of vi.
Lab exercises Each chapter's material will be reinforced with exercises that put the new skills to work. Labs will include practice with grep, vi, awk, sed, and perl.

Course outline

1. RE Overview

  • What are regular expressions?
  • Why go to the trouble?
  • What REs can and cannot do
  • Tools that use regexes
  • A big grain of salt

2. The Basics

  • Matching any one Character
  • Escaping Characters
  • Character Classes
  • POSIX and I18N
  • Anchors and Quanifiers
  • How to pronounce a regex

3. Advanced Topics

  • Extended regexes
  • Matching a range of occurrences
  • Range shortcuts
  • Matching whole words
  • Ignoring case
  • Grouping and Alternate choices
  • Subexpressions
Click here to see downloadable files for this course