2

How would I get the text between Listen | > and 1? I have tried a lot of examples I found online, but this always returns issues, this version has the issue:

AttributeError: 'NoneType' object has no attribute 'group'

Code:

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))


 

1 Answer 1

1

The regex pattern you want here is:

\bListen \| >\s*(.*?)\s*1\)

Using re.findall, we can try:

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)

This prints:

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.