Sunday, May 19, 2024
 Popular · Latest · Hot · Upcoming
32
rated 0 times [  36] [ 4]  / answers: 1 / hits: 17364  / 10 Years ago, tue, march 11, 2014, 12:00:00

I'm still in the process of learning some decent regex but I would have thought this would work.



This works:



str.replace(/   /g,).replace(/(rn|n|r)/gm,);


But a shorter version of this, does not. Where did I go wrong?



str.replace((/  /g)|(/(rn|n|r)/gm),);

More From » regex

 Answers
33

The regexpr delimiter is /, so you have the or | out of the expression. If you want to join them try with



str.replace((/  |rn|n|r/gm),);


By the way, the tab character is t in a regexp, so if you want to remove all tabs and new lines you can use str.replace(/[tnr]/gm,''); Said this, if with tab you mean any identation including 4 white spaces, then use str.replace(/ {4}|[tnr]/gm,'');


[#72057] Sunday, March 9, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
leslijessalyng

Total Points: 650
Total Questions: 85
Total Answers: 109

Location: Croatia
Member since Mon, Sep 6, 2021
3 Years ago
leslijessalyng questions
Fri, Feb 21, 20, 00:00, 4 Years ago
Tue, Jul 30, 19, 00:00, 5 Years ago
Fri, Jul 5, 19, 00:00, 5 Years ago
Wed, Mar 13, 19, 00:00, 5 Years ago
;