It stop at the word by itself or followed by a space. That way you don't trigger the regex if someone says, for example "colorful" or "colourful"
I used to utilize the word boundary \b, but it doesn't stop punctuation characters from triggering it to what I call it a "false positive." A sentence usually consists of many words in this format: "word1 word2 word3," so ( |$) will make sure it either proceeds with a space or ends the word as is.
It also allows you to use $2 if you don't want to use $regml() to refer to the value.