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:
“and”instead of"‘and’instead of'
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:
- copy a snippet out of a Word doc, Google Doc, or PDF
- paste code from a chatbot's rendered output
- type code in an editor with smart-quote autocorrect turned on
How to fix them
Find and replace. In your editor, replace each curly character with its straight equivalent:
“and”become"‘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
- Turn off smart quotes in your editor for code files.
- Clean any snippet you copy from a document or chatbot before pasting it into your project.
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.