3 ms·
I pasted your comment here into GPT-4o and asked for the Python equivalent, it suggested this which seems to work well: import regex as re def gra
by simonw 2y ago
I pasted your comment here into GPT-4o and asked for the Python equivalent, it suggested this which seems to work well:
import regex as re
def grapheme_clusters(text):
# \X is the regex pattern that matches a grapheme cluster
pattern = re.compile(r'\X')
return [
match.group(0)
for match in
pattern.finditer(text)
]
https://chatgpt.com/share/481c9c94-0431-4fcb-82aa-a44a4f3c21a3 https://chatgpt.com/share/481c9c94-0431-4fcb-82aa-a44a4f3c21...
- AlotOfReading 2y agoNote that regex is not the re module from the stdlib, it's a separate third party module that exposes the more powerful capabilities of PCRE like grapheme clustering directly.
- simonw 2y agoThat's a good callout, here's the docs for \X in that regex module: https://github.com/mrabarnett/mrab-regex?tab=readme-ov-file#matching-a-single-grapheme-x https://github.com/mrabarnett/mrab-regex?tab=readme-ov-file#...