How can i merge the following into one regex?
str
.replace(/(\r\n|\n|\r)/gm,"") // get rid of line breaks
.replace(/\s/g, ""); // get rid of spaces
I want to call replace() once and take care of both in same regex
How can i merge the following into one regex?
str
.replace(/(\r\n|\n|\r)/gm,"") // get rid of line breaks
.replace(/\s/g, ""); // get rid of spaces
I want to call replace() once and take care of both in same regex
I guess you only need to be using \s
... that normally includes [\r\n\t\f ]
, so the first replace is basically useless.
regexr.com is a great tool for testing regular expressions as it explains what each part does. for example if you hover over a /s
it will tell you that it matches line breaks as well.