Hashtag in PY
Match hashtags (# followed by word characters) in social media posts, including accented Latin characters.
Try it in the PY tester →Pattern
regexPY
#([\w\u00C0-\u024F]+) (flags: g)Python (re) code
pyPython
import re
pattern = re.compile(r"#([\w\u00C0-\u024F]+)")
input_text = "Loving #JavaScript and #regex!"
for m in pattern.finditer(input_text):
print(m.group(0))Stdlib `re` module — no third-party dependency. Works on Python 3.6+.
How the pattern works
# matches the literal hash. The capturing group ([\w\u00C0-\u024F]+) matches one or more word characters (letters, digits, underscore) plus Latin Extended Unicode range for accented characters like #café or #naïve.
Examples
Input
Loving #JavaScript and #regex!Matches
#JavaScript#regex
Input
Post tagged #café and #naïveMatches
#café#naïve
Input
No hashtags hereNo match
—