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!看看这个教程,以及如何询问技巧,比如如何写一个好的标题。
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区分大小写。
更多回答
我是一名优秀的程序员,十分优秀!