我怎样才能得到“听”和“1”之间的课文?我尝试了很多我在网上找到的例子,但是这总是会返回问题,这个版本有问题:
AttributeError: 'NoneType' object has no attribute 'group'
代码:
text = "1 (2 points) fa] 4) Listen | > Apache Cassandra is an open source NoSQL distributed database that delivers scalability and high availability without compromising performance and is trusted by thousands of companies. Linear scalability and proven fault tolerance on 1) commodity hardward © 2) ubuntu Os) ovals"
import re
result = re.search('Listen;(.*)1', text)
if result is not None:
print(result.group(1))
发布于 2021-10-25 22:31:39
这里您想要的正则表达式是:
\bListen \| >\s*(.*?)\s*1\)
使用re.findall
,我们可以尝试:
text = "1 (2 points) fa] 4) Listen | > Apache Cassandra is an open source NoSQL distributed database that delivers scalability and high availability without compromising performance and is trusted by thousands of companies. Linear scalability and proven fault tolerance on 1) commodity hardward © 2) ubuntu Os) ovals"
output = re.findall(r'\bListen \| >\s*(.*?)\s*1\)', text)[0]
print(output)
这些指纹:
Apache是一个开源的NoSQL分布式数据库,它在不影响性能的情况下提供可伸缩性和高可用性,并且受到数千家公司的信任。
上的线性可伸缩性和已证明的容错性
https://stackoverflow.com/questions/69718352
复制