Ravi
Ravi

Reputation: 737

Python regex matching multiple lines

I'm trying to get the contents of a <ul> tag from a webpage in python. I used the following code:
matchResult = re.search(r'<ul\s*content="MSL">(.*)</ul>', queryResult, re.MULTILINE)
This does not work. However if I remove the line breaks by using
queryResult = queryResult.replace('\r','').replace('\n','')
It works.

This regular expression in PHP works fine without removing line breaks: preg_match('@<ul\s*content="MSL">(.*)</ul>@msU', $queryResult, $matches);

How can I match over multiple lines using Python?

Upvotes: 1

Views: 1447

Answers (1)

jtbandes
jtbandes

Reputation: 118781

Include the re.DOTALL option as well, that will allow the . character to match newlines.

Upvotes: 5

Related Questions