I have a regex expression that captures the text from a text file. The regex can ve viewed at the following URL: https://regex101.com/r/wwEjTF/1
In my python code I would like extract the text that is matched by the regex only from all the other text in the text file. I have following python code for matching th regex and storing it in a variable.
match = re.findall(r'test\s.+\n\sdescription\s\"(.+)\"', text, re.S)
I am expecting all the matches to be in the match variable and returned a list.
But when I do print (match) I get empty list. I do not understand why it is coming up an empty list. How do i capture the matched part of the regex into the variable.
Thanks for your help.
Just in case if there is an issue with the above url, is the regex and the sample text string:
test\s.+\n\sdescription\s\"(.+)\"
some random text test 111.333.555.666 description "text10" some random text some random text test 22.44.55.66 description "text12" some random text some random text test 77.77.88.99 description "text13" some random text some random text test 14.22.55.99 description "text16" some random text some random text test 13.33.55.66 description "text17" some random text`
re.S. Because re.S Make the '.' special character match any character at all, including a newline; without this flag, '.' will match anything except a newline. And I think your.+is consuming everything.re.Sand still the same issue.description? Try:re.findall(r'test\s.+\n\s+description\s"(.+)"', text, re.S)