Reputation: 3429
I was replacing new line with the following javascript code:
str.replace(/(\r\n|\n|\r)/gm," ")
However, came across some Unicode new line Unicode Character 'NEXT LINE (NEL)' (U+0085).
How to remove new lines from a string safely i.e. all these weird new lines will be removed as well?
Is it an established API for javascript?
Upvotes: 0
Views: 819
Reputation: 888
\u
You can reference unicode characters by prepending \u to the unicode sequence. So U+0085
-> \u0085
const str = 'Need space here ->\u0085<-';
str = str.replace(/\u0085/g, ' ');
console.log(str)
// Output: Need space here -> <-
Here a nice read by flavio if you want to further explore dealing with Unicode chars: https://flaviocopes.com/javascript-unicode/
Hope this helps
Upvotes: 1