我將如何獲得 Listen | 之間的文本 > 和 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))
uj5u.com熱心網友回復:
你想要的正則運算式模式是:
\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 Cassandra 是一種開源 NoSQL 分布式資料庫,可在不影響性能的情況下提供可擴展性和高可用性,并受到數千家公司的信賴。線性可擴展性和經過驗證的容錯
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/336990.html
