我无法理解如何在 python 中使用命名反向引用。我想查找一月至三月的所有引用及其缩写形式(例如一月、一月、二月、二月等)
str = 'Bob Martin brought a car on January 20, 1962. On Feb. the 23rd, Bob sold his car. The 21st of March will be fun.'
re.findall('''
(?P<Month> (Jan(uary|\.)) | (Feb(ruary|\.)) | (Mar(ch|\.))) # Months
| (?P=Month)\sthe\s\d{2}(rd|st)
| [Tt]he\s\d{2}(rd|st)\sof(?P=Month)
'''
str, re.X")
应该匹配:
一月
2月23日
3月21日