189. Advanced Regular Expressions with re
import re
# Match 'Python' only if followed by 'Rocks'
pattern = r"Python(?= Rocks)"
text = "Python Rocks is amazing!"
matches = re.findall(pattern, text)
print(matches) # Output: ['Python']import re
# Match 'Python' only if not followed by 'Rocks'
pattern = r"Python(?! Rocks)"
text = "Python is fun, but Python Rocks too!"
matches = re.findall(pattern, text)
print(matches) # Output: ['Python']Last updated