gpt4 book ai didi

a second repetition to an inner repetition in re module in python(对python中re模块中的内部重复的第二次重复)

转载 作者:bug小助手 更新时间:2023-10-24 18:56:32 26 4
gpt4 key购买 nike



import re
grades = 'AAABBBACBACCCCCAABCABACCCCAABCBBCA'
re.findall('(?:a{3})*', grades)

here i want to find all strings which are multiples of three 'a' characters, however the result is a list of '', i.e.

在这里,我想要查找的所有字符串都是三个‘a’字符的倍数,但结果是一个‘’的列表,即


['', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '']

[‘’,‘’,‘’]


This syntax is from the re documentation

此语法来自Re文档



To apply a second repetition to an inner repetition, parentheses may be used. For example, the expression (?:a{6})* matches any multiple of six 'a' characters.



i don't know where is wrong, can you help me?

我不知道哪里不对,你能帮我吗?


i expect it to be ['AAA'] while the result is obviously not.

我预计会是[‘AAA’],而结果显然不是。


更多回答

BTW, welcome to Stack Overflow! Check out the tour, and How to Ask for tips, like how to write a good title.

顺便说一句,欢迎来到Stack Overflow!看看这个教程,以及如何询问技巧,比如如何写一个好的标题。

Possible duplicates: Why empty string is added in the output array while matching a string using regex pattern in javascript?, Why does String.match( / \d*/ ) return an empty string?, Regex: ignore case sensitivity and quite a few more.

可能的重复:为什么在使用正则表达式模式匹配字符串时在输出数组中添加空字符串?,为什么String.Match(/\d*/)返回空字符串?,正则表达式:忽略区分大小写,等等。

优秀答案推荐

Zero is a multiple of three. To exclude zero-length matches, use "one or more", +.

零是三的倍数。要排除零长度匹配,请使用“一个或多个”,+。


(?:A{3})+

Also note that regex is case-sensitive.

还要注意,regex区分大小写。


更多回答

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