Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why use ^[\s\u200c]+|[\s\u200c]+$ to trim spaces? [closed]

Tags:

regex

I came across some code recently where the following regex was being used to trim spaces (and \u200c) from the start and end of a string.

Is there a good reason to use a regex, or can I replace it with a trim() function?

like image 996
fredley Avatar asked Jul 20 '16 20:07

fredley


1 Answers

\u200c is the zero width non-joiner character, which trim() does not consider whitespace (at least in Java). You should probably use trim() unless you expect zero width non-joiner characters at the beginning or end of your input and you want to remove them - apparently StackOverflow does have this requirement.

like image 193
Kiwi Avatar answered Nov 10 '22 07:11

Kiwi