Python Forum

Full Version: Scrape multiple lines with regex
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
basically i wish to scrape content between two tags with mulitiple lines in between, ignoring other tags until it matches the one i look for.

i know (.*?) works for some content between two tags.
There's a flag for that (M or MULTILINE or (?m)).

import re

re.compile('X.*?Y', re.M)
What do you mean by tag? You're not trying to parse HTML with a regex, are you? That's generally a bad idea. Parsers designed for HTML are much better.
Regex against HTML/XML is not a good combination,a funny read.
There is a reason why parsers exist eg BeautifulSoup,lmxl...ect.
Parsers mention over can also take regex as help if needed.
Have a tutorial here.