How to Remove Hidden Characters From ChatGPT Text
Three ways to do it: paste it into the cleaner below, do it by hand with a regex in your editor, or call the API from a script.
The one-step way
Your text is processed in memory and never stored. See the full list of characters this removes.
Method 1: paste it in
Use the box above. Paste the text, press the button, copy the result. It handles every category at once and tells you what it found. This is the right answer for a one-off document.
Method 2: find and replace in your editor
If you would rather not paste your text into a website, every good editor can do this with a regular expression. Turn on regex search and replace the invisible ranges with nothing, then replace the exotic spaces with an ordinary space.
- VS Code: enable the .* regex toggle, search for the zero-width and format ranges, replace with nothing
- Then search the space ranges separately and replace with a single ordinary space, because deleting them would join words together
- Sublime Text and JetBrains editors use the same syntax
- Word and Google Docs cannot express these ranges; paste through a plain-text editor first
Order matters: strip the invisibles first, then fold the spaces. Doing it the other way round can leave a zero-width character sitting where a space used to be.
Method 3: from a script
If this is part of a publishing pipeline, do it in code. The API takes a POST with your text and returns the cleaned version plus a count of what it found, so you can log how much is being caught and fail loudly if something changes.
How to tell whether you have a problem at all
The usual symptoms: a search that should match does not, a CSV import puts everything in one column, code throws a syntax error on a line that looks perfectly fine, or two strings that appear identical compare as different. Any of those and it is worth checking.
FAQ
Frequently asked questions
- Why does my ChatGPT code throw a syntax error?
- Very often because a non-breaking space (U+00A0) or narrow no-break space (U+202F) landed in the indentation. Python raises an IndentationError or a non-printable character error; the line looks perfect because the character is invisible. Cleaning the text fixes it.
- Will removing hidden characters break my formatting?
- No. Invisible characters are deleted, and exotic spaces are folded to an ordinary space rather than removed, so word boundaries survive. Emoji are left intact. The zero-width joiners that hold a family emoji together are preserved when they sit between emoji rather than between letters.
- Do I need to do this every time?
- Only if your source produces them. Run the detector on a typical sample from your workflow; if it comes back clean, you have nothing to fix.
Last reviewed .