JavaScript trim line breaks with regex?
问题 I am using Google Translate to translate the contents of a textarea and fill another textarea with the API response. In my source textarea I am replacing the /n newlines with <br /> line breaks to send the query like this: var query = $('#textarea-src').val(); var query = encodeURIComponent(query); var query = query.replace(/\n\r?/g, '<br />'); // replace new lines with line breaks Then I make the call to Google: $.ajax({ url: apiUrl, dataType: 'jsonp', success: function(data) { var response