Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python Regex将于1985年6月15日被捕_Python_Regex - Fatal编程技术网

Python Regex将于1985年6月15日被捕

Python Regex将于1985年6月15日被捕,python,regex,Python,Regex,我想用1985年6月15日的表格来记录所有的日期 我使用的正则表达式显然是错误的,但不确定问题出在哪里。非常感谢您的帮助 re.findall("\b\d{1,2}\s\D+\s([2][0]\d\d|[1][9]\d\d)\b" 我的逻辑是: \b | starts the expression d{1,2} | 1 or 2 digits \s | space \D+ | any non digit character, no limit \s | space ([2][0]\d\d|[1

我想用1985年6月15日的表格来记录所有的日期

我使用的正则表达式显然是错误的,但不确定问题出在哪里。非常感谢您的帮助

re.findall("\b\d{1,2}\s\D+\s([2][0]\d\d|[1][9]\d\d)\b"
我的逻辑是:

\b | starts the expression
d{1,2} | 1 or 2 digits
\s | space
\D+ | any non digit character, no limit
\s | space
([2][0]\d\d|[1][9]\d\d) | the year 19xx or 20xx
\b | end boundary
这可能会有帮助

import re
s = "I'm trying to catch all dates with the form 15 Jun 1985."
print(re.findall(r"\b\d{1,2}\s[A-Za-z]+\s\d{4}\b", s))
输出:

['15 Jun 1985']
这可能会有帮助

import re
s = "I'm trying to catch all dates with the form 15 Jun 1985."
print(re.findall(r"\b\d{1,2}\s[A-Za-z]+\s\d{4}\b", s))
输出:

['15 Jun 1985']

您的正则表达式匹配,但您正在使用

从文件中

如果模式中存在一个或多个组,则返回组列表

这样你就有了1985年

您可以做什么使您的捕获组成为非捕获组,并将其写得更紧凑:


您的正则表达式匹配,但您正在使用

从文件中

如果模式中存在一个或多个组,则返回组列表

这样你就有了1985年

您可以做什么使您的捕获组成为非捕获组,并将其写得更紧凑:


试试看关于findall(r“\b\d{1,2}\s+(?:一月、二月、马[ry]、四月、朱[nl]、八月、九月、十月、十一月、十二月)s+(?:20 | 19)\d\d\b)、s、re.I)关于findall(r’(\d+)(\w+)(\d+),“今天是1985年6月15日,我认为你的代码明显错了吗?现在是1985年6月15日。您正在使用并且在您的正则表达式中有一个捕获组
()
。您可以将其设置为非捕获组
(?:)
。非常感谢。我接受了关于芬达尔的解释的答案。
re.findall(r“\b\d{1,2}\s+(?:一月、二月、马[ry]|四月、朱[nl]|八月、九月、十月、十一月、十二月)s+(?:20\d\b)、s、re.I)
re.findall+(\w+)(\w+),“今天是1985年6月15日,我认为你的意思显然是错的?现在是1985年6月15日。您正在使用并且在您的正则表达式中有一个捕获组
()
。您可以将其设置为非捕获组
(?:)
。非常感谢。我接受了解释的答案w+不允许数字进入我只想要文本的中间项吗?在这种情况下,你可以使用
print(re.findall(r“\b\d{1,2}\s[A-Za-z]+\s\d{4}\b”,s))
不允许数字进入我只想要文本的中间项吗?在这种情况下,你可以使用
print(re.findall(r\b\d{1,2}\s[A-Za-z]+\s\d{4}\b“,s))