I thought about regular expressions that are conscious of Japanese date and time notation and American date and time notation. There may be a bug, but a memorandum. It's a little unreasonable for the English-style day-month-year format, but I haven't seen it. In the last year, month, day, hour, minute, and second, I was able to hit the python regular expression for the time being. Why is it so troublesome? ..
'\\s*(?:[12][0-9]|3[01]|0?[1-9])\\s*?(?:th\\s*)?[Day\\-/\\.,]?'
'\\s*(?:(?:1[0-2]|0?[1-9])\\s*?[Moon\\-/\\.,]?|(?:Jan(?:uary|\\.)?|Feb(?:ruary|\\.)?|Mar(?:ch|\\.)?|Apr(?:il|\\.)?|May\\.?|Jun[e|\\.]?|Jul[y|\\.]?|Aug(?:ust|\\.)?|Sep(?:tember|\\.)?|Oct(?:ober|\\.)?|Nov(?:ember|\\.)?|Dec(?:ember|\\.)?)\\s*)'
'\s*(?:\d{4}|[\']?\d{2})\s*[Year\-/\.,]?'
From Taika to Reiwa
'\\s*(?:[ABDEHIKM-PR-UWYZ]\\.?|[Manku Inui, Genna, Genna, Treasure, Treasure, Hiroshi Hei, Nobuhiro, Keio, Keio, Masaaki, Eiji, Shirakami, Shirakami, Shirakami][Hisakiri Orchards, Hua Tuo, Hua Tuo, Hua Tuo, Kuniyasu, Treasure, Hironobu Hiranobu, Keisei Keisei, Civilization, Masatake, Eiji, Yasushi, Shoroku][Victory god]?[Character treasure cloud]?)\\s*?(?:\\d{1,2}|Former)[Year\\-/\\.,]?'
'\\s*(?:1[0-9]|2[0-4]||0?[0-9])\\s*?[\\.:Time]?'
'\\s*(?:[1-5][0-9]|0?[0-9])\\s*?[\\.:Minutes]?'
'\\s*(?:[1-5][0-9]|0?[0-9])\\s*?(?:Seconds|[Ss]ec(?:onds)?)?'
'\\s*(?:\\(?[Sunday Monday Tuesday Wednesday Thursday Friday Saturday](?:Dayoftheweek)?\\)?|(?:Sun|Mon|Tues?|Wed(?:nes)?|Thu(?:rs)?|Fri|Sat(?:ur))(?:day)?[\\.,]?)'
'(?:\\s*(?:1[0-9]|2[0-4]||0?[0-9])\\s*?[\\.:Time]?\\s*(?:[1-5][0-9]|0?[0-9])\\s*?[\\.:Minutes]?\\s*(?:[1-5][0-9]|0?[0-9])\\s*?(?:Seconds|[Ss]ec(?:onds)?)??\\s*(?:[,\\.]?\\d+)?(?:\\s*(?:[+\\-]\\d{4})\\s*\\(?(?:[ABCDEFGHIJKLMNOPRSTUVWY][ABCDEFGHIJKLMNOPRSTUVWXYZ][ABCDGHKLMNORSTUVWZ][1DST][T])\\)?|\\s*(?:[+\\-]\\d{4})|\\s*\\(?(?:[ABCDEFGHIJKLMNOPRSTUVWY][ABCDEFGHIJKLMNOPRSTUVWXYZ][ABCDGHKLMNORSTUVWZ][1DST][T])\\)?)?)'
"(?:(?:\\s*(?:\\d{4}|[']?\\d{2})\\s*[Year\\-/\\.,]?|\\s*(?:[ABDEHIKM-PR-UWYZ]\\.?|[Manku Inui, Genna, Genna, Treasure, Treasure, Hiroshi Hei, Nobuhiro, Keio, Keio, Masaaki, Eiji, Shirakami, Shirakami, Shirakami][Hisakiri Orchards, Hua Tuo, Hua Tuo, Hua Tuo, Kuniyasu, Treasure, Hironobu Hiranobu, Keisei Keisei, Civilization, Masatake, Eiji, Yasushi, Shoroku][Victory god]?[Character treasure cloud]?)\\s*?(?:\\d{1,2}|Former)[Year\\-/\\.,]?)\\s*(?:(?:1[0-2]|0?[1-9])\\s*?[Moon\\-/\\.,]?|(?:Jan(?:uary|\\.)?|Feb(?:ruary|\\.)?|Mar(?:ch|\\.)?|Apr(?:il|\\.)?|May\\.?|Jun[e|\\.]?|Jul[y|\\.]?|Aug(?:ust|\\.)?|Sep(?:tember|\\.)?|Oct(?:ober|\\.)?|Nov(?:ember|\\.)?|Dec(?:ember|\\.)?)\\s*)\\s*(?:[12][0-9]|3[01]|0?[1-9])\\s*?(?:th\\s*)?[Day\\-/\\.,]?\\s*(?:\\(?[DayMoon火水木金土](?:曜Day)?\\)?|(?:Sun|Mon|Tues?|Wed(?:nes)?|Thu(?:rs)?|Fri|Sat(?:ur))(?:day)?[\\.,]?)?|\\s*(?:\\(?[DayMoon火水木金土](?:曜Day)?\\)?|(?:Sun|Mon|Tues?|Wed(?:nes)?|Thu(?:rs)?|Fri|Sat(?:ur))(?:day)?[\\.,]?)?(?:\\s*(?:\\d{4}|[']?\\d{2})\\s*[Year\\-/\\.,]??(?:\\s*(?:(?:1[0-2]|0?[1-9])\\s*?[Moon\\-/\\.,]?|(?:Jan(?:uary|\\.)?|Feb(?:ruary|\\.)?|Mar(?:ch|\\.)?|Apr(?:il|\\.)?|May\\.?|Jun[e|\\.]?|Jul[y|\\.]?|Aug(?:ust|\\.)?|Sep(?:tember|\\.)?|Oct(?:ober|\\.)?|Nov(?:ember|\\.)?|Dec(?:ember|\\.)?)\\s*)\\s*(?:[12][0-9]|3[01]|0?[1-9])\\s*?(?:th\\s*)?[Day\\-/\\.,]?|\\s*(?:[12][0-9]|3[01]|0?[1-9])\\s*?(?:th\\s*)?[Day\\-/\\.,]?\\s*(?:(?:1[0-2]|0?[1-9])\\s*?[Moon\\-/\\.,]?|(?:Jan(?:uary|\\.)?|Feb(?:ruary|\\.)?|Mar(?:ch|\\.)?|Apr(?:il|\\.)?|May\\.?|Jun[e|\\.]?|Jul[y|\\.]?|Aug(?:ust|\\.)?|Sep(?:tember|\\.)?|Oct(?:ober|\\.)?|Nov(?:ember|\\.)?|Dec(?:ember|\\.)?)\\s*))|(?:\\s*(?:(?:1[0-2]|0?[1-9])\\s*?[Moon\\-/\\.,]?|(?:Jan(?:uary|\\.)?|Feb(?:ruary|\\.)?|Mar(?:ch|\\.)?|Apr(?:il|\\.)?|May\\.?|Jun[e|\\.]?|Jul[y|\\.]?|Aug(?:ust|\\.)?|Sep(?:tember|\\.)?|Oct(?:ober|\\.)?|Nov(?:ember|\\.)?|Dec(?:ember|\\.)?)\\s*)\\s*(?:[12][0-9]|3[01]|0?[1-9])\\s*?(?:th\\s*)?[Day\\-/\\.,]?|\\s*(?:[12][0-9]|3[01]|0?[1-9])\\s*?(?:th\\s*)?[Day\\-/\\.,]?\\s*(?:(?:1[0-2]|0?[1-9])\\s*?[Moon\\-/\\.,]?|(?:Jan(?:uary|\\.)?|Feb(?:ruary|\\.)?|Mar(?:ch|\\.)?|Apr(?:il|\\.)?|May\\.?|Jun[e|\\.]?|Jul[y|\\.]?|Aug(?:ust|\\.)?|Sep(?:tember|\\.)?|Oct(?:ober|\\.)?|Nov(?:ember|\\.)?|Dec(?:ember|\\.)?)\\s*))\\s*(?:\\d{4}|[']?\\d{2})\\s*[Year\\-/\\.,]?))"
"(?:(?:\\s*(?:\\d{4}|[']?\\d{2})\\s*[Year\\-/\\.,]?|\\s*(?:[ABDEHIKM-PR-UWYZ]\\.?|[Manku Inui, Genna, Genna, Treasure, Treasure, Hiroshi Hei, Nobuhiro, Keio, Keio, Masaaki, Eiji, Shirakami, Shirakami, Shirakami][Hisakiri Orchards, Hua Tuo, Hua Tuo, Hua Tuo, Kuniyasu, Treasure, Hironobu Hiranobu, Keisei Keisei, Civilization, Masatake, Eiji, Yasushi, Shoroku][Victory god]?[Character treasure cloud]?)\\s*?(?:\\d{1,2}|Former)[Year\\-/\\.,]?)\\s*(?:(?:1[0-2]|0?[1-9])\\s*?[Moon\\-/\\.,]?|(?:Jan(?:uary|\\.)?|Feb(?:ruary|\\.)?|Mar(?:ch|\\.)?|Apr(?:il|\\.)?|May\\.?|Jun[e|\\.]?|Jul[y|\\.]?|Aug(?:ust|\\.)?|Sep(?:tember|\\.)?|Oct(?:ober|\\.)?|Nov(?:ember|\\.)?|Dec(?:ember|\\.)?)\\s*)\\s*(?:[12][0-9]|3[01]|0?[1-9])\\s*?(?:th\\s*)?[Day\\-/\\.,]?\\s*(?:\\(?[DayMoon火水木金土](?:曜Day)?\\)?|(?:Sun|Mon|Tues?|Wed(?:nes)?|Thu(?:rs)?|Fri|Sat(?:ur))(?:day)?[\\.,]?)?|\\s*(?:\\(?[DayMoon火水木金土](?:曜Day)?\\)?|(?:Sun|Mon|Tues?|Wed(?:nes)?|Thu(?:rs)?|Fri|Sat(?:ur))(?:day)?[\\.,]?)?(?:\\s*(?:\\d{4}|[']?\\d{2})\\s*[Year\\-/\\.,]??(?:\\s*(?:(?:1[0-2]|0?[1-9])\\s*?[Moon\\-/\\.,]?|(?:Jan(?:uary|\\.)?|Feb(?:ruary|\\.)?|Mar(?:ch|\\.)?|Apr(?:il|\\.)?|May\\.?|Jun[e|\\.]?|Jul[y|\\.]?|Aug(?:ust|\\.)?|Sep(?:tember|\\.)?|Oct(?:ober|\\.)?|Nov(?:ember|\\.)?|Dec(?:ember|\\.)?)\\s*)\\s*(?:[12][0-9]|3[01]|0?[1-9])\\s*?(?:th\\s*)?[Day\\-/\\.,]?|\\s*(?:[12][0-9]|3[01]|0?[1-9])\\s*?(?:th\\s*)?[Day\\-/\\.,]?\\s*(?:(?:1[0-2]|0?[1-9])\\s*?[Moon\\-/\\.,]?|(?:Jan(?:uary|\\.)?|Feb(?:ruary|\\.)?|Mar(?:ch|\\.)?|Apr(?:il|\\.)?|May\\.?|Jun[e|\\.]?|Jul[y|\\.]?|Aug(?:ust|\\.)?|Sep(?:tember|\\.)?|Oct(?:ober|\\.)?|Nov(?:ember|\\.)?|Dec(?:ember|\\.)?)\\s*))|(?:\\s*(?:(?:1[0-2]|0?[1-9])\\s*?[Moon\\-/\\.,]?|(?:Jan(?:uary|\\.)?|Feb(?:ruary|\\.)?|Mar(?:ch|\\.)?|Apr(?:il|\\.)?|May\\.?|Jun[e|\\.]?|Jul[y|\\.]?|Aug(?:ust|\\.)?|Sep(?:tember|\\.)?|Oct(?:ober|\\.)?|Nov(?:ember|\\.)?|Dec(?:ember|\\.)?)\\s*)\\s*(?:[12][0-9]|3[01]|0?[1-9])\\s*?(?:th\\s*)?[Day\\-/\\.,]?|\\s*(?:[12][0-9]|3[01]|0?[1-9])\\s*?(?:th\\s*)?[Day\\-/\\.,]?\\s*(?:(?:1[0-2]|0?[1-9])\\s*?[Moon\\-/\\.,]?|(?:Jan(?:uary|\\.)?|Feb(?:ruary|\\.)?|Mar(?:ch|\\.)?|Apr(?:il|\\.)?|May\\.?|Jun[e|\\.]?|Jul[y|\\.]?|Aug(?:ust|\\.)?|Sep(?:tember|\\.)?|Oct(?:ober|\\.)?|Nov(?:ember|\\.)?|Dec(?:ember|\\.)?)\\s*))\\s*(?:\\d{4}|[']?\\d{2})\\s*[Year\\-/\\.,]?))(?:\\s+|[T:])(?:\\s*(?:[AaPp]\\.?[Mm]\\.?|Horse[Beforeandafter])?\\s*(?:1[0-9]|2[0-4]||0?[0-9])\\s*?[\\.:Time]?\\s*(?:[1-5][0-9]|0?[0-9])\\s*?[\\.:Minutes]?\\s*(?:[1-5][0-9]|0?[0-9])\\s*?(?:Seconds|[Ss]ec(?:onds)?)??\\s*(?:[,\\.]?\\d+)?(?:\\s*(?:[+\\-]\\d{4})\\s*\\(?(?:[ABCDEFGHIJKLMNOPRSTUVWY][ABCDEFGHIJKLMNOPRSTUVWXYZ][ABCDGHKLMNORSTUVWZ][1DST][T])\\)?|\\s*(?:[+\\-]\\d{4})|\\s*\\(?(?:[ABCDEFGHIJKLMNOPRSTUVWY][ABCDEFGHIJKLMNOPRSTUVWXYZ][ABCDGHKLMNORSTUVWZ][1DST][T])\\)?)?\\s*(?:[AaPp]\\.?[Mm]\\.?|Horse[Beforeandafter])?)"
#Japanese style
"2001/08/24"
"August 24, 2001"
"2001/08/24 20:10"
"Friday, August 24, 2001 20:10"
"August 24, 2001(Money) 20:10"
"August 24, 1st year of Reiwa PM 08:10"
"August 24, 1st year of Reiwa PM08:10:"
"August 24, 1st year of Reiwa 8 pm:10"
"Reiwa 2nd year 08/24 pm 08:10"
#American style mm-dd-yy
"08-24-2001"
"Friday, August 24th, 2001"
"Fri Aug. 24, 2001 8:10 p.m."
"Fri Aug. 24, 2001 20:10"
#Japanese style
"August 24, 1st year of Reiwa 8:10" ->Judgment is strange when characters of hour, minute and second are entered
#American style mm-dd-yy
"08-24-01" -> 01(hour)It has been judged to be (How to write 2001 with a 2-digit year ...)
Recommended Posts