Last time, we discussed Deterministic Finite Automata. One interesting application of these mathematical objects is found in computer science: Regular Expressions. \\
Often enough, a clever regex pattern can do the work of a few hundred lines of code. \\
\vspace{2mm}
Like the DFAs we have studied, a regex pattern \textit{accepts} or \textit{rejects} a string. However, we don't usually use this terminology when discussing regex, instead opting to say a pattern \textit{matches} or \textit{doesn't match} a string. \\
\vspace{5mm}
\textbf{Quantifiers}\\
Quantifiers tell us how many of a character to match. \\
There are four of them:
\htexttt{+}, \htexttt{*}, \htexttt{?}, and \htexttt{\{\}}
\vspace{2mm}
\htexttt{+} means \say{match one or more of the preceding token}\\
\htexttt{*} means \say{match zero or more of the preceding token}\\
For example, the pattern \htexttt{ca+t} will match the following strings:
\begin{itemize}
\item\texttt{cat}
\item\texttt{caat}
\item\texttt{caaaaaaaat}
\end{itemize}
\htexttt{ca+t} will \textbf{not} match the string \texttt{ct}. \\
The pattern \htexttt{ca*t} will match all the strings above, including \texttt{ct}.
\hint{The special token \texttt{\textbackslash w} will match any word character. It is equivalent to \texttt{[A-z0-9\_]}\\\texttt{\_} stands for a literal underscore.}
If you'd like to know more, check out \texttt{regexr.com}. It offers an interative regex prompt, as well as a cheatsheet that explains every other regex token there is. You will find a nice set of challenges at \texttt{http://regex.alf.nu}. \\