So what I am trying to do is replace one or more instances of newline with the br tag in javascript. So far I have:
description.replace(/\n/g, '<br />');
However if there is a case where there are 2/3 newlines’s in a row I get 2/3 br tags. Is there a way in regex to say give me any instances of one or more newlines’s in a row and replace that whole thing with one br tag so that even if I have:
\n\n\n\n\n\n\n\n\n
that would get replace with just:
<br >
You can add the
+quantifier to indicate one or more matches.PS: you need to read more about regular expressions, this was fairly straight forward.