/L (Locale-dependent)
What is /L (Locale-dependent)?
/L (Locale-dependent): Makes \w, \b, \s (and case conversion) depend on the current C locale rather than a fixed Unicode/ASCII table. The L flag, found in Python for byte patterns, makes classes such as \w and case-insensitive matching follow the current system locale. A server set to a Turkish or French locale can then treat letters differently from one set to English.
Frequently asked questions about /L (Locale-dependent)
How is /L (Locale-dependent) used in practice?
That is exactly why it is rarely a good idea. The same code can behave differently on your laptop, the CI server and production, depending on environment settings nobody remembers to check. Bugs like that are slow to find.
What should you keep in mind with /L (Locale-dependent)?
Python 3 discourages the flag for text and only allows it for bytes. Use Unicode-aware matching, which is the default for str patterns, or the ASCII flag when you need strict rules. Both give the same result on every machine. If you inherit code with re.LOCALE, treat it as a small risk to clean up rather than a feature to keep.
At a glance
| Category | Regex flags |
|---|---|
| Explained by | Reinier de la Parra |
| Updated |