Back to all patterns
Python Identifier
Validation
Matches a Python identifier (ASCII; PEP 8 ASCII recommendation).
/^[A-Za-z_][A-Za-z0-9_]*$/How it works
Python 3 actually allows Unicode identifiers, but PEP 8 recommends ASCII for portability. This regex enforces ASCII-only, letters, digits, underscore, no leading digit.
Test Cases
Should Match
- snake_case
- _private
- Class1
- x
Should NOT Match
- 1abc
- with-hyphen
- spaces here
Quick Summary
Validates ASCII-only Python identifiers per PEP 8.