import re
pattern = re.compile( r'''(?xs)
(?<!')(?:'{2})*\B('\b[^'\\]*(?:(?:\\.|\b'\b)[^'\\]*)*') # Single quoted string literal
|                                         # or
(?<!")(?:"{2})*\B("\b[^"\\]*(?:(?:\\.|\b"\b)[^"\\]*)*") # Double quoted string literal
''')

text = "I am \"looking for\" a way that doesn't break: \"Lorem\nipsum\\\" AAAAA\" in this case. Or this AAAAA case. Or this 'AAAAA' case.\nIsn't this annoying?"
print(f"This is the text: {text}")
matches = [f'{x}{y}' for x,y in pattern.findall(text) if 'AAAAA' in f'{x}{y}']
print(matches)

## h ttps://regex 101.com/r/AlFzPT/1/