string = string.replace(/[&\/\\#,+()$~%.'":*?<>{}]/g, '');
string = string.replace(/[^a-zA-Z0-9]/g, '');
This is the code that I found online. I am little confused about it. How come first line of code "excludes" special characters whereas 2nd line only include those characters that are only in []. Both functions are "replace" then how come they are doing totally opposite work.