textscrubr
Home / Blog / Developers

How to Strip Zero-Width Characters in VS Code

Developers2 min readUpdated 2026-06-24
To strip zero-width characters in VS Code, enable Unicode highlighting to reveal them, then use Find and Replace in regex mode to search for [\u200B-\u200D\u2060\uFEFF] and replace with nothing. VS Code also flags non-ASCII and ambiguous characters so you can spot them before they break your code.

VS Code is one of the better places to hunt zero-width characters, because it can both reveal and remove them. Here is how.

Reveal them first

VS Code has built-in Unicode highlighting that flags suspicious invisible and ambiguous characters. It is on by default in many setups, but you can confirm and tune it:

With highlighting on, a zero-width character that was breaking your build becomes visible as a marked spot in the line.

Remove them with Find and Replace

  1. Open Find and Replace (Ctrl/Cmd + H).
  2. Turn on regex mode (the .* button).
  3. Search for [\u200B-\u200D\u2060\uFEFF].
  4. Leave replace empty and replace all.

This removes zero-width spaces, joiners, the word joiner, and the byte-order mark from the file. If your code uses the zero-width joiner intentionally (for emoji), narrow the pattern to exclude \u200D.

Remove a BOM

If the file starts with a byte-order mark, the cleanest fix is to change the encoding: click the encoding indicator in the status bar, choose Save with Encoding, and pick UTF-8 (not "UTF-8 with BOM").

Do it across the project

To clean many files, use the Search panel (Ctrl/Cmd + Shift + F), enable regex, search for the same pattern, and replace across the workspace. Review the matches first so you do not strip an intentional joiner.

For a quick check outside VS Code

If you just want to confirm what is in a snippet, paste it into a cleaner like textscrubr, which lists the zero-width and invisible characters it finds and strips them, keeping the emoji joiners intact. It is a fast sanity check before or after cleaning in the editor.

Prevent it

Keep Unicode highlighting on, and clean any code you paste from a document or chatbot before it enters your project, so zero-width characters never reach the build in the first place.

Scrub this text in one click

textscrubr strips the hidden characters, em dashes, and double spaces, and keeps your lists, headings, and code exactly where you put them. Free, and it runs entirely in your browser.

Clean my text free →

Frequently asked questions

How do I see zero-width characters in VS Code?

Enable Editor > Unicode Highlight: Invisible Characters in settings. VS Code marks zero-width and other invisible characters with a highlight so you can find them in the line.

How do I remove zero-width characters in VS Code?

Open Find and Replace, turn on regex mode, search for [\u200B-\u200D\u2060\uFEFF], and replace with nothing. Use the Search panel to do it across the whole project.

How do I remove a BOM in VS Code?

Click the encoding indicator in the status bar, choose Save with Encoding, and pick UTF-8 (not 'UTF-8 with BOM'). That drops the byte-order mark from the file.