Let's say we have a string
string="This is a test code [asdf -wer -a2 asdf] >(ascd asdfas -were)\
(testing test) test >asdf \
re.findall(r'>[^)](.*)test',string, re.MULTILINE )
(ascd asdfas -were)\ test \ (testing test) test >asdf.
(ascd asdfas -were)\
import re s="""This is a test code [asdf -wer -a2 asdf] >(ascd asdfas -were) test (testing test) test >asdf test""" print(re.findall(r'>(.*?)\btest\b', s, re.DOTALL))
['(ascd asdfas -were)\n', 'asdf\n']
The only somewhat interesting parts of this pattern are:
.*"ungreedy", otherwise you'd have a single, long match instead of two.
\btest\bas the "ending" identifier (see Jan's comment below) instead of
\bMatches the empty string, but only at the beginning or end of a word....
Note, it may be reading up on
re.DOTALL, as I think that's really what you want.
. characters include newlines, while
MULTILINE lets anchors (
$) match start and end of lines instead of the entire string. Considering you don't use anchors, I'm thinking
DOTALL is more appropriate.