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?
Include the re.DOTALL
option as well, that will allow the .
character to match newlines.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.