With Ruby regular expressions (RegExp), a question mark matches zero or one of the things that came before it. So :? matches one colon or no colon.

Also, the m flag (which goes after the closing slash of a regex) turns on newline-matching for the full-stop/period/dot.