This thread suggests using \p
to match punctuation and the comments suggest it works. But I could not find it in the official documentation and this code fails for me in Python 2.7.10 or Python 3.7.0:
import re
s = """
ABCD?
"""
print("with p: " + str(re.search(r"\n[A-Z \\p]+\n", s)))
print("with ?: " + str(re.search(r"\n[A-Z ?]+\n", s)))
The result is:
with p: None
with ?: <_sre.SRE_Match object at 0x1039afbf8>
Does Python have a special sequence to match punctuation?