This is an archived version of the course. Please find the latest version of the course on the main webpage.

Chapter 5: Exercises

Summary

face Josiah Wang

Ok, I have provided you with the basics of regular expressions. Hopefully are able to write your own regular expressions by now!

As a recap, here are the special metacharacters for regular expressions in Python.

  • .: Match any characters except a newline.
  • ?: Match zero or one repetitions
  • *: Match zero or more repetitions
  • +: Match one or more repetitions
  • [ ]: Match a set of characters
  • ( ): Grouping
  • |: Or
  • {m}: Match exactly m repetitions
  • {m,n}: Match m to n repetitions. Omitting n will give you infinity.
  • ^: Match the start of a string, or “not” if used inside [ ].
  • $: Match the end of a string
  • \b: Word boundary marker. Remember to use raw strings r"\b" or escape it "\\b" when using this in Python.
  • \: Escape characters. Use this to represent any of the metacharacters above (e.g. "\?" if you want to match a question mark). Escaping is not needed inside square brackets.