function escapeRegExp(string) {
  return string.replace(/[.*+?^${}()|[\]\\]/g, "\\$&"); // $& means the whole matched string
}
Escapes regular expression special characters from a string by replacing them with their escaped counterparts.

@param {string} string The string to escape.
@returns {string} The escaped string.