gpt4 book ai didi

java - 正则表达式来识别所有日期

转载 作者:行者123 更新时间:2023-12-02 05:31:51 25 4
gpt4 key购买 nike

我正在尝试识别 DAY MONTH YEAR、DAY MONTH、MONTH YEAR 和 YEAR 格式的所有可能的日期表达式

我的正则表达式:[0-9]{0,2}([Jj]anuary | [Ff]ebruary | [Mm]arch | [Aa]pril | [Mm]ay | [Jj]une | [Jj]七月 | [Aa]八月 | [Ss]九月 | [Oo]十月 | [Nn]十一月 | [Dd]十二月 ){0,1}[0-9]{4}缺少表达式 DAY MONTH

如何修复它?

最佳答案

尝试下一个:

(?i)(?<=\s|^)((\d{1,2} )?(january|february|march|april|may|june|july|august|september|october|november|december)( \d{4})?)|\d{4}(?=\s|$)
<小时/>

您可能想在http://rick.measham.id.au/paste/explain.pl中查看并解释这个正则表达式。

NODE                     EXPLANATION
----------------------------------------------------------------------------
(?i) set flags for this block (case-
insensitive) (with ^ and $ matching
normally) (with . not matching \n)
(matching whitespace and # normally)
----------------------------------------------------------------------------
(?<= look behind to see if there is:
----------------------------------------------------------------------------
\s whitespace (\n, \r, \t, \f, and " ")
----------------------------------------------------------------------------
| OR
----------------------------------------------------------------------------
^ the beginning of the string
----------------------------------------------------------------------------
) end of look-behind
----------------------------------------------------------------------------
( group and capture to \1:
----------------------------------------------------------------------------
( group and capture to \2 (optional
(matching the most amount possible)):
----------------------------------------------------------------------------
\d{1,2} digits (0-9) (between 1 and 2 times
(matching the most amount possible))
----------------------------------------------------------------------------
' '
----------------------------------------------------------------------------
)? end of \2 (NOTE: because you are using a
quantifier on this capture, only the
LAST repetition of the captured pattern
will be stored in \2)
----------------------------------------------------------------------------
( group and capture to \3:
----------------------------------------------------------------------------
january 'january'
----------------------------------------------------------------------------
| OR
----------------------------------------------------------------------------
february 'february'
----------------------------------------------------------------------------
| OR
----------------------------------------------------------------------------
march 'march'
----------------------------------------------------------------------------
| OR
----------------------------------------------------------------------------
april 'april'
----------------------------------------------------------------------------
| OR
----------------------------------------------------------------------------
may 'may'
----------------------------------------------------------------------------
| OR
----------------------------------------------------------------------------
june 'june'
----------------------------------------------------------------------------
| OR
----------------------------------------------------------------------------
july 'july'
----------------------------------------------------------------------------
| OR
----------------------------------------------------------------------------
august 'august'
----------------------------------------------------------------------------
| OR
----------------------------------------------------------------------------
september 'september'
----------------------------------------------------------------------------
| OR
----------------------------------------------------------------------------
october 'october'
----------------------------------------------------------------------------
| OR
----------------------------------------------------------------------------
november 'november'
----------------------------------------------------------------------------
| OR
----------------------------------------------------------------------------
december 'december'
----------------------------------------------------------------------------
) end of \3
----------------------------------------------------------------------------
( group and capture to \4 (optional
(matching the most amount possible)):
----------------------------------------------------------------------------
' '
----------------------------------------------------------------------------
\d{4} digits (0-9) (4 times)
----------------------------------------------------------------------------
)? end of \4 (NOTE: because you are using a
quantifier on this capture, only the
LAST repetition of the captured pattern
will be stored in \4)
----------------------------------------------------------------------------
) end of \1
----------------------------------------------------------------------------
| OR
----------------------------------------------------------------------------
\d{4} digits (0-9) (4 times)
----------------------------------------------------------------------------
(?= look ahead to see if there is:
----------------------------------------------------------------------------
\s whitespace (\n, \r, \t, \f, and " ")
----------------------------------------------------------------------------
| OR
----------------------------------------------------------------------------
$ before an optional \n, and the end of
the string
----------------------------------------------------------------------------
) end of look-ahead

关于java - 正则表达式来识别所有日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25458258/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com