Regex between quotes look ahead - Python
Question: I have this:

    
    
    myText = str(^123"I like to"^456&U"play video games and"$"eat cereal")
    

I want to extract everything in between (and including) quotation marks, split
everything before and after the `$` sign, and append them into a nested list.
E.g.

myTextList = [["I like to","play video games and"],["eat cereal"]]

This is what I tried:

    
    
    tempTextList = []
    for text in re.findall('(?<=\$)"[^"]*"(?<!\^)',myText,re.DOTALL)
        tempTextList.append(text)
    myTextList.append(tempTextList)
    

I used the website <https://www.regex101.com/#python> and tried almost
everything I could think of...

`(?!\$)"(?!\^\00\+\-\&)[^"].*"` etc...

The re.findall part doesn't really work the way I want it to.

Can someone point me in the right direction?

Thanks


Answer: You can use `"[^"]*"` regex with `re.findall`:

    
    
    import re
    s = 'myText = str(^123"I like to"^456&U"play video games and"$"eat cereal")'
    print(re.findall(r'"[^"]*"', s))
    

See [demo](http://ideone.com/2EmIcf)

It matches the double quoted substrings you need with double quotes: `['"I
like to"', '"play video games and"', '"eat cereal"']`.

Note that `"[^"]*"` matches `"` followed by zero or more characters other than
`"` followed with `"`.

If you need to get the contents inside `"..."` without the double quotes, you
can use _capturing_ mechanism:

    
    
    r'"([^"]*)"'
    

The [`re.findall`](https://docs.python.org/2/library/re.html#re.findall) will
only return the captures in Group 1. See [another
demo](http://ideone.com/aidLq5).

