FIX: Prevent infinite loop when replacing watched words (PR #12967)

Super rare, but a bad regex could cause some serious issues.

GitHub

:heart_eyes:

I would not call this the index but rather count since it’s counting the number of matches?

Tricky but you can do this as well

        ++index < maxMatches