Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

946
Views
How to remove \u200B (Zero Length Whitespace Unicode Character) from String in Java?

My application is using Spring Integration for email polling from Outlook mailbox.

As, it is receiving the String (email body)from an external system (Outlook), So I have no control over it.

For Example,

String emailBodyStr= "rejected by sundar14-\u200B.";

Now I am trying to remove the unicode character \u200B from this String.

What I tried already.

Try#1:

emailBodyStr = emailBodyStr.replaceAll("\u200B", "");

Try#2:

`emailBodyStr = emailBodyStr.replaceAll("\u200B", "").trim();`

Try#3 (using Apache Commons):

StringEscapeUtils.unescapeJava(emailBodyStr);

Try#4:

StringEscapeUtils.unescapeJava(emailBodyStr).trim();

Nothing worked till now.

When I tried to print this String using below code.

logger.info("Comment BEFORE:{}",emailBodyStr);
logger.info("Comment AFTER :{}",emailBodyStr);

In Eclipse console, it is NOT printing unicode char,

Comment BEFORE:rejected by sundar14-​.

But the same code prints the unicode char in Linux console as below.

Comment BEFORE:rejected by sundar14-\u200B.

I read some examples where str.replace() is recommended, but please note that examples uses javascript, PHP and not Java.

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Finally, I am able to remove 'Zero Width Space' character by using 'Unicode Regex'.

String plainEmailBody = new String();
plainEmailBody = emailBodyStr.replaceAll("[\\p{Cf}]", "");

Reference to find the category of Unicode characters.

  1. Character class from Java.

Character class from Java lists all of these unicode categories.

enter image description here

  1. Website: http://www.fileformat.info/

Character category

  1. Website: http://www.regular-expressions.info/ => Unicode Regular Expressions

Unicode Regex for \u200B character

Note 1: As I received this string from Outlook Email Body - none of the approaches listed in my question was working.

My application is receiving a String from an external system (Outlook), So I have no control over it.

Note 2: This SO answer helped me to know about Unicode Regular Expressions .

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!