Tôi đang sử dụng regex sau để khớp với các mẫu ngày khác nhau. nó hoạt động tốt trong regex101.com. Nhưng khi tôi nhập khẩu vào python tôi đang nhận được "phạm vi nhân vật xấu" ngoại lệ.Python regex phạm vi ký tự xấu.
pattern = ur"((?:\b((?:(january|jan|february|feb|march|mar|april|apr|may|jun|june|july|jul|august|aug|september|set|sep|october|oct|november|nov|december|dec)['\s\.]{0,4}(?:\d{4}|\d{2})|(?:january|jan|february|feb|march|mar|april|apr|may|jun|june|july|jul|august|aug|september|set|sep|october|oct|november|nov|december|dec)|((?:0[1-9]|[1-3][0-9]|[0-9])/(?:0[1-9]|[1-3][0-9])/(?:(19[7-9][0-9])|(20[0-1][0-9])|([7-9][0-9]|[0-1][0-9]))|((?:0[1-9]|1[0-2]|[1-9])\s{0,3}[-/']{1,3}[\s-/']{0,3}(?:(19[7-9][0-9])|(20[0-1][0-9])|([7-9][0-9]|[0-1][0-9])))))(?:(?![\r\n])\s){0,4})[-/–to]{0,2}(?:(?![\r\n])\s){0,4}(((?:january|jan|february|feb|march|mar|april|apr|may|jun|june|july|jul|august|aug|september|set|sep|october|oct|november|nov|december|dec)[-'\s\.]{0,4}(?:(19[7-9][0-9])|(20[0-1][0-9])|([7-9][0-9]|[0-1][0-9])))|((?:0[1-9]|[1-3][0-9]|[1-9])/(?:0[1-9]|[1-3][0-9])/(?:(19[7-9][0-9])|(20[0-1][0-9])|([7-9][0-9]|[0-1][0-9])))|((?:0[1-9]|1[0-2]|[1-9])\s{0,3}[-/']{1,3}[\s-/']{0,3}(?:(19[7-9][0-9])|(20[0-1][0-9])|([7-9][0-9]|[0-1][0-9]))))))"
https://regex101.com/r/rU3cE9/1
Bạn đang chạy phiên bản python nào? –
@AvinashRaj - Tôi bao gồm rất nhiều dấu gạch nối. Tôi có một nghi ngờ rằng, nó sẽ không được vì dấu gạch nối thường xuyên (-) phải không? Nhưng, làm thế nào đến regex101.com không hiển thị một lỗi. – user3116355
@AvinashRaj - Tôi đang sử dụng python 2.7 – user3116355