how do i remove all the illegal characters with regular expression in javascript? how should the regex look like? i am not very good with regex.

i am trying to do like str.replace('\([\w][\d])*\g', '');
i was thinking if i could do a condition in regex where i could say if the character is not alphanumeric, i will replace it with an empty char. but i have no idea how to do that.