How can I define a regex to find multiline comments in python that contain the word "xyz". Example for a string that should match:
"""
blah blah
blah
xyz
blah blah
"""
I tried this regex:
"""((.|\n)(?!"""))*?xyz(.|\n)*?"""
(grep -i -Pz '"""((.|\n)(?!"""))?xyz(.|\n)?"""')
but it was not good enough. for example, for this input
"""
blah blah blah
blah
"""
# xyz
def foo(self):
"""
blah
"""
it matched this string:
"""
# xyz
def foo(self):
"""
The expected behavior in this case it to not match anything since "xyz" is not inside a comment block.
I wanted it to only find "xyz" within opening quotes and closing quotes, but the string it matches is not inside a quotes block. It matches a string that starts with a quote, has "xyz" in it and ends with a quote, but the matched string is NOT inside a python comment block.
Any idea how to get the required behavior from this regex?