Reputation: 85
I have a string with opening and closing double quotes which in some cases do match. e.g.
“paints to what my predecessors, samba girl’ and “2nd baby toy” have ably pointed out...
In the above string the double quotes before paint is not closed because “2nd baby toy” begins another quote and closes. Is there a regex that returns only matching open and close quotes and ignores unclosed quotes? In this case I would only it to return 2nd baby toy
instead of paints to what my predecessors, samba girl’ and “2nd baby toy
.
Most solution for extracting string inside brackets or quotes used regex re.findall('\“(.+?)\”', _some_text)
which in my example above returns most of the string.
Upvotes: 0
Views: 73
Reputation: 20737
This regex would do it:
“([^“”]+)”
“
- find the opening quote([^“”]+)
- Find everything which is not an opening nor closing quote”
- find the closing quotehttps://regex101.com/r/lALDFZ/1
Upvotes: 2