the '$' event prefix means the matching text is a regular expression, the regular expression, by default, match anywhere in the string, if you want to enforce the start of the string, use '^', the m parameter is not required if you use the default delimiter '/' and ! does not need to be escaped:
That being said, you do not need a regular expression to match that, you can use wildcard:
Although that won't strip the control code like the S modifier is with a regular expression. It is not recommended to use regular expression if you don't understand them