I've been looking for a way to find the nearest encasing quotes or double quotes of a phrase in a paragraph. For example, for the phrase -> AAAAA:
I am "looking for" a way that doesn't break: "Lorem
ipsum\" AAAAA" in this case. Or this AAAAA case. Or this 'AAAAA' case.
Isn't this annoying?
The output would be:
"Lorem ipsum \" AAAAA" | AAAAA | 'AAAAA'
I'm really looking for any good way to do it (regex/parser or any valid method will be gladly accepted).
I tried to get some inspiration from How can I match a quote-delimited string with a regex?, but it wasn't really what I was looking for.
An example for something I tried was this (and then use code to filter out matches that include the "AAAAA" in them. This failed though when there was another ' in the end of the sentence.:
(["'])(?:\\\1|[\s\S])*?(AAAAA)?(?:\\\1|[\s\S])*?\1|AAAAA
If it's any help, I'm going to be using this solution in Python code.
Thanks!