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

I recently met code where the following regular expression was used to align spaces (and \u200c ):

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

+7
regex
source share
1 answer

\u200c is a zero-width character without participation , which trim() does not consider spaces ( at least in Java ). You should probably use trim() if you are not expecting zero character widths without access at the beginning or end of your input, and you want to delete them - obviously, StackOverflow has this requirement.

+2
source share

All Articles