首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >获取两个子字符串之间的文本

获取两个子字符串之间的文本
EN

Stack Overflow用户
提问于 2021-10-26 06:28:08
回答 1查看 42关注 0票数 1

我怎样才能得到“听”和“1”之间的课文?我尝试了很多我在网上找到的例子,但是这总是会返回问题,这个版本有问题:

代码语言:javascript
复制
AttributeError: 'NoneType' object has no attribute 'group'

代码:

代码语言:javascript
复制
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))
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2021-10-26 06:31:39

这里您想要的正则表达式是:

代码语言:javascript
复制
\bListen \| >\s*(.*?)\s*1\)

使用re.findall,我们可以尝试:

代码语言:javascript
复制
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分布式数据库,它在不影响性能的情况下提供可伸缩性和高可用性,并且受到数千家公司的信任。

上的线性可伸缩性和已证明的容错性

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/69718352

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档