how to make this regex grab the entire string in the middle without being cut if it detects, points.
, commas ,
, colons :
or semicolons;
The only case where the regex should not grab the text is if there is a line break between the set ends
import re
input_text = "cerca de abbaab como estas?. Creo yo que bien,aunque solo haya 9 de ellas pero : no estoy muy segura ccccrrru, y luego..."
some_text = "\s*((?:\w\s*)+)\s*" #need to fix this
regex_pattern = r"(?:abbaab)" + some_text + r"(?:ccccrrru)"
m1 = re.search(regex_pattern, input_text, re.IGNORECASE)
if(m1):
association = m1.group()
print(repr(association)) #output
And the correct output is:
' como estas?. Creo yo que bien,aunque solo haya 9 de ellas pero : no estoy muy segura '
And how should I modify the regex to cover line breaks as well? For example for this input:
input_text = """cerca de abbaab como estas?.
Creo yo que bien,aunque solo haya 9 de ellas.
pero : no estoy muy segura ccccrrru, y luego...
Quizas sea."""
And the correct output for this case is:
' como estas?.
Creo yo que bien,aunque solo haya 9 de ellas.
pero : no estoy muy segura '