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?
\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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With