Skip to content

Instantly share code, notes, and snippets.

@miguelteixeiraa
Last active May 8, 2023 15:34
Show Gist options
  • Save miguelteixeiraa/19fd8cd2998e5d1f1e3d32c8e0fc6842 to your computer and use it in GitHub Desktop.
Save miguelteixeiraa/19fd8cd2998e5d1f1e3d32c8e0fc6842 to your computer and use it in GitHub Desktop.
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