Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/311.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/20.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 正则表达式从字符串中查找的所有匹配项_Python_Regex_Substring - Fatal编程技术网

Python 正则表达式从字符串中查找的所有匹配项

Python 正则表达式从字符串中查找的所有匹配项,python,regex,substring,Python,Regex,Substring,我有字符串: 瑞士卡萨布兰卡文本,2041年现金1234e 我想提取长度至少为4的所有字母数字值(数字必选),包括或不包括特殊字符/\\\:。\- 下面是我尝试过的正则表达式 (?=.{4,}$)(?=.[0-9])([a-zA-Z0-9/\\\\\\\:.\-\]+)$ 但是,只有当它是字符串中的最后一个时,它才捕获所需的模式。 我想捕获所有的值。在这种情况下,2041和1234e 我尝试了来自世界各地的解决方案,但没有一个奏效 \b(?=[a-zA-Z]*\d)[a-zA-Z0-9/\\_:

我有字符串:

瑞士卡萨布兰卡文本,2041年现金1234e

我想提取长度至少为4的所有字母数字值(数字必选),包括或不包括特殊字符
/\\\:。\-

下面是我尝试过的正则表达式

(?=.{4,}$)(?=.[0-9])([a-zA-Z0-9/\\\\\\\:.\-\]+)$

但是,只有当它是字符串中的最后一个时,它才捕获所需的模式。 我想捕获所有的值。在这种情况下,
2041
1234e

我尝试了来自世界各地的解决方案,但没有一个奏效

\b(?=[a-zA-Z]*\d)[a-zA-Z0-9/\\_:.\-|]{4,}\b
尝试此操作。
$
仅导致找到最后一个匹配项。
\b
将标记单词边界,您将获得所有匹配项。请参阅演示


加上VKS的答案,正则表达式无法匹配字符串
absrd.910.824

我试过这个,效果很好

正则表达式:
\b(?=[a-zA-Z/\\\-.\124;]*\ d[a-zA-Z0-9/\\\\\\\-.\124;]{4,}\b

如果存在两个字母数字字符串,则只选择第一个。示例字符串,
Philippe Columbus 57s2 COLVMBVS CCSTRH8不锈钢
@Vaulstein,它会同时选择这两个字符串。请参见此处使用
re.findall
@Vaulstein try
(?:^ |)(?@Vaulstein,这将查找位于开头或结尾或周围有空格的单词+其他条件。您也可以尝试使用新字符串