[PYTHON] Date notation regular expression

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? ..

Regular expression that hits day

'\\s*(?:[12][0-9]|3[01]|0?[1-9])\\s*?(?:th\\s*)?[Day\\-/\\.,]?'

Regular expression that hits the month

'\\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*)'

Regular expression that hits the year

'\s*(?:\d{4}|[\']?\d{2})\s*[Year\-/\.,]?'

Regular expression that hits the first year of the Japanese calendar (gengo)

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\\-/\\.,]?'

Regular expression that hits the hour

'\\s*(?:1[0-9]|2[0-4]||0?[0-9])\\s*?[\\.:Time]?'

Regular expression that hits the minute

'\\s*(?:[1-5][0-9]|0?[0-9])\\s*?[\\.:Minutes]?'

Regular expression that hits seconds

'\\s*(?:[1-5][0-9]|0?[0-9])\\s*?(?:Seconds|[Ss]ec(?:onds)?)?'

Regular expression that hits the day of the week

'\\s*(?:\\(?[Sunday Monday Tuesday Wednesday Thursday Friday Saturday](?:Dayoftheweek)?\\)?|(?:Sun|Mon|Tues?|Wed(?:nes)?|Thu(?:rs)?|Fri|Sat(?:ur))(?:day)?[\\.,]?)'

Regular expression that hits the time

'(?:\\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])\\)?)?)'

Regular expression that hits the date

"(?:(?:\\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\\-/\\.,]?))"

Regular expression that hits the year, month, day, hour, minute, and second

"(?:(?:\\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])?)"

Test OK pattern

#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"

Test NG pattern

#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

Date notation regular expression
Regular expression Greedy
Regular expression re
Regular expression in regex.h
Regular expression look-ahead, after-yomi
python regular expression memo
Regular expression matching method
Regular expression in Python
Regular expression in Python
Regular expression confirmation quiz!
0 Convert unfilled date to datetime type with regular expression
Python 處 處 regular expression Notes
Julia Quick Note [04] Regular Expression
Regular expression manipulation with Python
Regular expression check tool summary
I tried to make a regular expression of "date" using Python
Decompose hostname with co.jp with regular expression
String replacement with Python regular expression
100 language processing knocks 2020: Chapter 3 (regular expression)
Introduction to regular expression processing system
Start / end match in python regular expression
(Python) HTML reading and regular expression notes
Search pythondict dictionary key by regular expression