String to escape.
The escaped string safe for use in a RegExp constructor.
const user_input = 'example.com';
const pattern = new RegExp(escapeRegExp(user_input));
pattern.test('example.com'); // true
pattern.test('exampleXcom'); // false (. is literal, not wildcard)
// Without escaping, . would match any character
new RegExp(user_input).test('exampleXcom'); // true (. matches X)
Escapes special characters in a string for safe use in a regular expression.
This utility function escapes all characters that have special meaning in regular expressions, allowing you to safely use user input or dynamic strings as literal patterns.