Last active
May 8, 2023 15:34
-
-
Save miguelteixeiraa/19fd8cd2998e5d1f1e3d32c8e0fc6842 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
def is_valid_id_start(num): | |
"""Returns True if the Unicode character represented by num is a | |
valid ID_Start according to the Unicode specification, False otherwise.""" | |
pattern = re.compile(r'[$_\p{ID_Start}]', re.UNICODE) | |
return pattern.match(chr(num)) is not None | |
def is_valid_id_part(num): | |
"""Returns True if the Unicode character represented by num is a | |
ID_Continue according to the Unicode specification, False otherwise. | |
""" | |
pattern = re.compile(r"^\p{ID_Continue}$") | |
return pattern.match(chr(num)) is not None | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment