/a (ASCII-only)
What is /a (ASCII-only)?
/a (ASCII-only): Restricts \w, \b, \s, \d (and case-insensitive matching) to ASCII characters only, instead of full Unicode. The ASCII flag limits shorthand classes such as \w, \d, \s and \b to plain ASCII characters. In Python it is re.ASCII or (?a). Without it, Python 3 treats letters like é, ß and Chinese characters as word characters too.
Frequently asked questions about /a (ASCII-only)
How is /a (ASCII-only) used in practice?
That difference matters when you validate input. A pattern like ^\w+$ for a username will accept José by default, and reject it with the ASCII flag. Neither is wrong, but you should choose on purpose.
What should you keep in mind with /a (ASCII-only)?
For identifiers that end up in URLs, file names or older systems, ASCII-only rules avoid surprises further down the line. For names, addresses and any text written by people, full Unicode is usually what you want. Whatever you pick, test with a few accented and non-Latin examples, not just the English words you used while writing the pattern.
At a glance
| Category | Regex flags |
|---|---|
| Explained by | Reinier de la Parra |
| Updated |