0

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?

1

1 Answer 1

1

Unicode in regular expressions with \u

You can reference unicode characters by prepending \u to the unicode sequence. So U+0085 -> \u0085

Example:

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.