textscrubr
Home / Blog / Punctuation

How to Fix Curly Quotes That Break Your Code

Punctuation2 min readUpdated 2026-06-24
To fix curly quotes in code, replace them with straight quotes: search for the curly characters (“ ” ‘ ’) and replace with " and '. They usually sneak in from copying code out of a document or chatbot. A cleaner straightens all four at once and strips other invisible characters too.

Code that looks perfect but throws a syntax error is often the victim of a curly quote. Here is how to find and fix them.

Why curly quotes break code

Code expects straight quotes: " and '. A curly (smart) quote, the kind word processors and chatbots insert automatically, is a completely different character:

They look almost identical on screen, but the compiler or interpreter does not recognize them as string delimiters, so it throws an error that points to a line where everything looks correct.

Where they come from

Curly quotes sneak into code when you:

How to fix them

Find and replace. In your editor, replace each curly character with its straight equivalent:

  1. and become "
  2. and become '

Copy each curly character from your code into the search box, since you usually cannot type them directly.

Use a cleaner. Faster and more complete: paste the code into a cleaner that straightens quotes. textscrubr replaces all four curly characters at once and, importantly, also strips the invisible characters (like zero-width spaces) that often accompany the same paste and cause equally baffling errors. It leaves your code spacing and indentation untouched.

Prevent it

Spotting them

If your editor supports it, enable a setting that highlights non-ASCII or ambiguous characters. Many editors flag curly quotes and other lookalikes, so you can see them before they break the build.

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

Why do curly quotes break my code?

Because code expects straight quotes (" and '). A curly quote is a different character, so the compiler does not recognize it as a string delimiter and throws a syntax error even though the line looks correct.

How do I replace curly quotes with straight quotes in code?

Find-and-replace each curly character (“ ” ‘ ’) with its straight equivalent, or paste the code into a cleaner that straightens all four at once and strips other invisible characters.

How did curly quotes get into my code?

Usually from copying a snippet out of a document or chatbot, or typing with smart-quote autocorrect on. Turn off smart quotes for code files and clean any pasted snippets.