|

Quick Tip: Replace Breakline (\n) with comma

Today I have a very quick tip but useful. I’ve wasted a few minutes of my life trying to find an answer for this because I’m not an expert when it comes to regular expressions.

This code comes in handy if you’re trying to remove \n (a break line) from a string and you want to replace it with something else (line a comma, as shown in the example below) you can use the following code:

string.replace(/[\r\n]+/g, ",");

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *