Indeed.  It would be worth
* testing regex to see if it's actually just a plain string, or genuinely a regex
* if it's a regex, compile the regex and use a substitute (I'm assuming we have one) for StringMatch that takes the compiled regex.
* otherwise, use strstr or some similar string function
This shall require two loops (one using regex, one using strstr), so it probably makes sense to move the loop body into a static function that both bodies can call.