Regex expression after quotation on python
Question: I am trying to develop a program on Python that would get the name of the
artists from a twit from Pandora. Like for example if I have this twitter:

> I'm listening to "I Can Make It Better" by Luther Vandross on Pandora
> #pandora <http://t.co/ieDbLC393F>.

I would like to get only the name Luther Vandross back. I do not know much
about regex, so I tried to do the following code:

    
    
    print  re.findall('".+?" by [\w+]+',  text)    
    

But the result was "I can Make it Better" by Luther

Do you have any idea on how I would be able to develop a regular expression on
python to get it?


Answer: Your regex is near, but you can change the delimiters to use `" by` and `on`.
However, you need to use capturing groups by using parentheses.

You can use a regex like this:

    
    
    " by (.+?) on
    

**[Working demo](https://regex101.com/r/oN1uJ8/1)**

![Regular expression
visualization](https://www.debuggex.com/i/WeaW9dGrXAk4T3Cw.png)

The idea behind this regex is to capture the content between the `" by` and
`on`, using a simple nongreedy regex.

Match information

    
    
    MATCH 1
    1.  [43-58] `Luther Vandross`
    

Code

    
    
    import re
    p = re.compile(ur'" by (.+?) on')
    test_str = u"I'm listening to \"I Can Make It Better\" by Luther Vandross on Pandora #pandora http://t.co/ieDbLC393F.\n"
    
    re.search(p, test_str)
    

