<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[my application]]></title><description><![CDATA[my application]]></description><link>https://7even.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Sat, 28 Nov 2026 20:32:09 GMT</lastBuildDate><atom:link href="https://7even.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Why Blindly Stripping Zero-Width Characters Breaks Emoji & Multilingual Text (And the Safe Regex)]]></title><description><![CDATA[If you have ever debugged a JSON.parse() failure where the payload looked completely valid on screen, you have probably met an invisible Unicode character.]]></description><link>https://7even.hashnode.dev/why-blindly-stripping-zero-width-characters-breaks-emoji-multilingual-text-and-the-safe-regex</link><guid isPermaLink="true">https://7even.hashnode.dev/why-blindly-stripping-zero-width-characters-breaks-emoji-multilingual-text-and-the-safe-regex</guid><category><![CDATA[unicode]]></category><category><![CDATA[JavaScript]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[Python]]></category><category><![CDATA[Regex]]></category><dc:creator><![CDATA[Seven GS]]></dc:creator><pubDate>Thu, 19 Nov 2026 06:59:57 GMT</pubDate><content:encoded><![CDATA[<p>If you have ever debugged a <code>JSON.parse()</code> failure where the payload looked completely valid on screen, you have probably met an invisible Unicode character.</p>
<p>Copy-pasting snippets from wikis, Google Docs, PDFs, or chat interfaces routinely sneaks characters like <code>U+200B</code> (Zero Width Space), <code>U+FEFF</code> (Byte Order Mark), <code>U+00AD</code> (Soft Hyphen), or <code>U+00A0</code> (Non-Breaking Space) into your strings. Because RFC 8259 JSON only allows four ASCII whitespace bytes (<code>0x20</code>, <code>0x09</code>, <code>0x0A</code>, <code>0x0D</code>), a single stray <code>U+00A0</code> outside a string literal crashes the parser.</p>
<h2>The Common Regex Mistake</h2>
<p>When developers search for a quick fix, the top copy-pasted regex on forums usually looks like this:</p>
<pre><code class="language-js">// Don't do this in production
const broken = input.replace(/[\u200B-\u200F\uFEFF]/g, "");
</code></pre>
<p>The range <code>\u200B-\u200F</code> accidentally catches U+200C (Zero Width Non-Joiner, ZWNJ) and U+200D (Zero Width Joiner, ZWJ)—and both are structurally required in modern Unicode:\</p>
<ul>
<li>Compound Emoji Sequences (U+200D): Emojis like <code>👩‍💻</code> (<code>👩</code> + <code>U+200D</code> + <code>💻</code>), <code>👨‍👩‍👧‍👦</code>, and <code>🏳️‍🌈</code> are glued together with <code>U+200D</code>. Strip it, and <code>👩‍💻</code> breaks apart into <code>👩💻</code>.</li>
<li>Indic &amp; Southeast Asian Scripts: Devanagari, Bengali, Malayalam, Sinhala, and Tamil rely on <code>U+200C</code> / <code>U+200D</code> for conjunct ligatures and half-forms.</li>
<li>Persian, Arabic, and Urdu: Rely on <code>U+200C</code> (ZWNJ) to stop adjacent characters inside compound words from merging into connected ligatures.</li>
</ul>
<p>3. Which Code Points to Strip vs. Preserve</p>
<table style="min-width:100px"><colgroup><col style="min-width:25px"></col><col style="min-width:25px"></col><col style="min-width:25px"></col><col style="min-width:25px"></col></colgroup><tbody><tr><td><p>Code Point</p></td><td><p>Unicode Name</p></td><td><p>Common Source</p></td><td><p>Safe Action</p></td></tr><tr><td><p>U+200B</p></td><td><p>Zero Width Space (ZWSP)</p></td><td><p>Rich-text editors, web copy</p></td><td><p>Remove</p></td></tr><tr><td><p>U+FEFF</p></td><td><p>Byte Order Mark (BOM)</p></td><td><p>Windows UTF-8 CSV/text exports</p></td><td><p>Remove</p></td></tr><tr><td><p>U+2060</p></td><td><p>Word Joiner (WJ)</p></td><td><p>Desktop publishing / Docs</p></td><td><p>Remove</p></td></tr><tr><td><p>U+00AD</p></td><td><p>Soft Hyphen (SHY)</p></td><td><p>PDFs &amp; hyphenated web layouts</p></td><td><p>Remove</p></td></tr><tr><td><p>U+00A0</p></td><td><p>No-Break Space (NBSP)</p></td><td><p>HTML &amp;nbsp;, Docs, macOS Option+Space</p></td><td><p>Replace with U+0020</p></td></tr><tr><td><p>U+202F</p></td><td><p>Narrow No-Break Space</p></td><td><p>Timestamps, French typography</p></td><td><p>Replace with U+0020</p></td></tr><tr><td><p>U+200C / U+200D</p></td><td><p>ZWNJ / ZWJ</p></td><td><p>Compound Emojis, Indic &amp; RTL scripts</p></td><td><p>Preserve</p></td></tr></tbody></table>

<p>4. Safe Cleanup Functions (JavaScript &amp; Python)<br />Use an explicit list of formatting artifacts rather than a broad range:</p>
<p>function cleanInvisibleUnicode(input) { return input .replace(/[\u200B\u2060\uFEFF\u00AD]/g, "") .replace(/[\u00A0\u202F\u2007]/g, " "); }</p>
<p>import re</p>
<p>TARGETS = { "\u200b": "ZWSP", "\ufeff": "BOM", "\u2060": "WJ", "\u00ad": "SHY", "\u00a0": "NBSP", }</p>
<p>def inspect_invisible(text: str): return [(i, f"U+{ord(ch):04X}", TARGETS[ch]) for i, ch in enumerate(text) if ch in TARGETS]</p>
<p>def clean_invisible(text: str) -&gt; str: text = re.sub(r"[\u200b\u2060\ufeff\u00ad]", "", text) return re.sub(r"[\u00a0\u202f\u2007]", " ", text)</p>
<p><br />Full Reference &amp; Browser Inspector<br />If you want the full write-up with worked JSON/slug debugging examples, I published a detailed guide on TextScope:<a href="https://textscopes.com/guides/remove-invisible-unicode-characters">How to Detect and Remove Invisible Unicode Characters Safely</a>.<br />And if you just need to paste a suspicious string and inspect which hidden code points are inside—100% locally in your browser without uploading your text—you can use the<a href="https://textscopes.com/ai-text-cleaner">TextScope AI Text &amp; Unicode Cleaner</a>(includes a code-point inspector, Markdown stripper, and one-click Undo).</p>
]]></content:encoded></item><item><title><![CDATA[Why Pretty JSON and CJK Prompts Burn Way More LLM Tokens (And How to Budget Context Windows)]]></title><description><![CDATA[If you build with GPT-4o, Claude, or Gemini APIs, word count is a poor proxy for token billing—especially when prompts mix English instructions…]]></description><link>https://7even.hashnode.dev/why-pretty-json-and-cjk-prompts-burn-way-more-llm-tokens-and-how-to-budget-context-windows</link><guid isPermaLink="true">https://7even.hashnode.dev/why-pretty-json-and-cjk-prompts-burn-way-more-llm-tokens-and-how-to-budget-context-windows</guid><dc:creator><![CDATA[Seven GS]]></dc:creator><pubDate>Thu, 19 Nov 2026 03:31:35 GMT</pubDate><content:encoded><![CDATA[<p>If you build with GPT-4o, Claude, or Gemini APIs, word count is a poor proxy for token billing—especially when prompts mix English instructions, pretty-printed JSON payloads, and CJK (Chinese, Japanese, Korean) text.</p>
<h2>How Subword Tokenization Inflates Token Counts</h2>
<p>Modern LLM tokenizers (<code>o200k_base</code>, <code>cl100k_base</code>, Claude BPE, and Gemini SentencePiece) assign single token IDs to common English words, but split symbols, indentation, and multi-byte UTF-8 characters into multiple subwords:</p>
<ul>
<li><strong>Standard English prose</strong>: <del>1.30–1.35 tokens per word (</del>4 characters/token)</li>
<li><strong>Spanish / German / Portuguese</strong>: ~1.55–1.85 tokens per word (diacritics and compound nouns split more often)</li>
<li><strong>Pretty-printed JSON</strong>: Repeated quotes, colons, braces, and 2-space indentation add 15%–30% extra tokens compared to minified JSON</li>
<li><strong>CJK scripts</strong>: Multi-byte characters typically consume 1.0–1.8 tokens per character</li>
</ul>
<h2>3 Quick Habits to Cut Prompt Bloat</h2>
<ol>
<li><strong>Minify JSON payloads</strong> before injecting them into system prompts.</li>
<li><strong>Strip Markdown clutter &amp; invisible clipboard noise</strong>: Copying drafts from chat UIs often drags in <code>**bold**</code> asterisks, <code>###</code> headings, and zero-width spaces (<code>U+200B</code>) that waste tokens and break exact-match keys. You can strip them locally in your browser using <a href="https://textscopes.com/ai-text-cleaner">TextScope AI Text Cleaner</a>, which removes stray zero-width characters while preserving compound Emoji <code>U+200D</code> joiners.</li>
<li><strong>Budget for</strong> <code>input + system + tools + reserved_output</code>: Never fill 99% of a 128K or 200K context window—always reserve headroom for completion tokens and API framing overhead.</li>
</ol>
<h2>Estimate Prompt Tokens Locally Without Server Uploads</h2>
<p>I built a lightweight, 100% client-side <a href="https://textscopes.com/token-counter">LLM Prompt Token Counter</a> as part of <a href="https://textscopes.com/">TextScope</a> so developers and writers can paste confidential prompts, JSON, or CJK text and check context window budgets locally in the browser without uploading anything to a server.</p>
]]></content:encoded></item></channel></rss>