ComedicChimera
ComedicChimera

Reputation: 476

Matching a Multiline Regex Pattern in Python

I have been trying to re.findall() over multiple lines and have been unable to do so. This is my regex.

rx = re.compile(r"```( )* test.+```", re.DOTALL)
list = rx.findall(string)

And all I am getting back is [' ']. (Side note, the string is read in from a file.) Can anyone explain what has gone wrong here?

I have also tried using re.DOTALL|re.MULTILINE as flags and they didn't solve anything either.

Upvotes: 0

Views: 62

Answers (1)

Knoep
Knoep

Reputation: 890

As pointed out by Michael Butscher, findall will return only what is matched by the group in your pattern. In your case, that is a single white space. If you want to get the whole match returned, try

r'``` +test.+```'

Upvotes: 1

Related Questions