javascript regex to escape special characters code example
Example 1: javascript escape regex
function escapeRegExp(input) {
const source = typeof input === 'string' || input instanceof String ? input : '';
return source.replace(/[-[/\]{}()*+?.,\\^$|#\s]/g, '\\$&');
}
Example 2: js string to regex
const regex = new RegExp('https:\\/\\/\\w*\\.\\w*.*', 'g');