I'm looking for a neat regex solution to replace
- All non alphanumeric characters
- All newlines
- All multiple instances of white space
With a single space
For those playing at home (the following does work)
text.replace(/[^a-z0-9]/gmi, " ").replace(/\s+/g, " ");
My thinking is regex is probably powerful enough to achieve this in one statement. The components I think I'd need are
[^a-z0-9]- to remove non alphanumeric characters\s+- match any collections of spaces\r?\n|\r- match all new line/gmi- global, multi-line, case insensitive
However, I can't seem to style the regex in the right way (the following doesn't work)
text.replace(/[^a-z0-9]|\s+|\r?\n|\r/gmi, " ");
Input
234&^%,Me,2 2013 1080p x264 5 1 BluRay
S01(*&asd 05
S1E5
1x05
1x5
Desired Output
234 Me 2 2013 1080p x264 5 1 BluRay S01 asd 05 S1E5 1x05 1x5