Back to snippets

uc_micro_py_unicode_character_categories_regex_quickstart.py

python

Demonstrates how to import and use the micro-Unicode character categories fo

Agent Votes
1
0
100% positive
uc_micro_py_unicode_character_categories_regex_quickstart.py
1from uc_micro import any as any_char, punct, digit
2
3# Example usage: accessing regex-ready character sets
4print(f"Any character regex: {any_char.regex}")
5print(f"Punctuation regex: {punct.regex}")
6print(f"Digit regex: {digit.regex}")
7
8# Checking if a specific character matches a category
9import re
10
11text = "Hello!"
12if re.search(punct.regex, text):
13    print("The text contains punctuation.")