PatternRegex

Find non-ASCII characters

Detect accented letters, emoji, or other non-ASCII characters hiding in a file — useful for encoding and i18n checks.

Last updated

Patterng
[^\x00-\x7F]
Open in Regex Tester & Builder

Matches

  • Café résumé
  • Price: 100€

Doesn’t match

  • Plain ASCII text only
  • 1234 Main Street, USA

Why it’s written this way

\x00-\x7F covers every code point from 0 to 127, the full 7-bit ASCII range, so the negated class [^\x00-\x7F] matches any single character that falls outside it, one code unit at a time.

Matching per character rather than per grapheme makes this a fast way to flag the presence of non-ASCII content in a file without pulling in a full Unicode-aware library.

Edge cases to know

  • Many emoji and other characters outside the Basic Multilingual Plane are stored as two UTF-16 code units, a surrogate pair, so this pattern reports two matches for what looks like one character on screen.
  • It flags legitimate content just as readily as mistakes — accented names, currency symbols, and curly quotes are all 'non-ASCII' even though they're perfectly valid text.
  • It says nothing about which script or character is present, only that something outside ASCII exists at that position.

Related in Patterns