Regular Expressions

Regular expression syntax is often used to describe sets of courses. This section is just a small part of what is used in the plan definitions and if you wish to learn more, check out For Plan Writers.

Here are some common rules you may see:

  • ^CS_135 matches one course, CS_135.
  • Square brackets match any of the characters they contain.
    • ^CS_1[134]5 matches any of CS_115, CS_135, or CS_145 but not CS_155.
  • A dot matches any character: ^CS_1.5 matches a total of ten courses: CS_105, CS_115, CS_125, …, CS_195. It would also match courses like CS_1u5 or even CS_1@5 if we had courses labeled like that!
  • ^CS_135 + ^CS_136 matches CS_135 or ^CS_136.
  • An asterisk, *, matches any number of what immediately precedes it. It often follows a dot, which matches any character.
    • ^CS_.* matches any CS course.
    • ^ENGL_108.* matches ENG_L108 (the .* matches 0 times) as well as ENGL_108A, ENGL_108B (useful), and ENGL_108ABBBB (not useful).
  • A plus, + is also like * except that it matches one or more (not zero) of what precedes it. This is different from the other useage of the + sign, that one represents a union of sets.
  • A question mark, ?, matches 0 or 1 occurrences of what precedes it. It’s probably the best way to represent something that is optional.
  • A “pipe”, |, is used for “or”. It’s often used with parentheses.
    • ^CS_(115|135|145) matches three CS courses.
    • ^(CS_|CO_)467 matches both CS_467 as well as CO_467.