sre_constants Module¶
The sre_constants module defines constants used internally by the regex engine and the sre_compile/sre_parse modules.
Complexity Reference¶
| Operation | Time | Space | Notes |
|---|---|---|---|
| Access constant | O(1) | O(1) | Static constants |
| Lookup opcode | O(1) | O(1) | Hash table |
Regex Engine Constants¶
Using Regex Constants¶
import sre_constants
# Access opcodes - O(1)
print(sre_constants.LITERAL) # Regular character
print(sre_constants.BRANCH) # | operator
print(sre_constants.RANGE) # Character range [a-z]
# View all opcodes
for name in dir(sre_constants):
if name.isupper():
print(f"{name}: {getattr(sre_constants, name)}")