using stored variables as regex patterns
Question: is there a way for python to use values stored in variables as patterns in
regex?

supposing i have two variables:

    
    
    begin_tag = '<%marker>'
    end_tag = '<%marker/>'
    
    doc = '<html> something here <%marker> and here and here <%marker/> and more here <html>'
    

how do you extract the text between begin_tag and end_tag?

the tags are determined after parsing another file, so they're not fixed.


Answer: Don't use a regex at all. parse html inteligently!

    
    
    from BeautifulSoup import BeautifulSoup
    marker = 'mytag'
    doc = '<html>some stuff <mytag> different stuff </mytag> other things </html>'
    soup = BeautifulSoup(doc)
    print soup.find(marker).renderContents()
    

