Source: http://www.bowdoin.edu/~smajerci/teaching/cs2210/2019spring/lectures/regular-or-not.pdf