How to extract string between selected string in python
Question: if i have a string like:

    
    
    str = 'Hello, <code>This is the string i want to extract</code>'
    

Then how will i extract string that are between `<code>` and `</code>`, In
above case the extract string is:

    
    
    'This is the string i want to extract'
    

I want to use this string in django filter.


Answer: Use a parser such as `BeautifulSoup`:

    
    
    >>> from bs4 import BeautifulSoup as BS
    >>> text = 'Hello, <code>This is the string i want to extract</code>'
    >>> soup = BS(text)
    >>> print soup.code.text
    This is the string i want to extract
    

Or you can just use regex if it's just one line:

    
    
    >>> import re
    >>> re.search(r'<code>(.*?)</code>', text).group(1)
    'This is the string i want to extract'
    

* * *

By the way, please don't name strings `str`. It will override the built-in
type.

