I want to detect some special sub string and also overlapping.I have a string from input and if the string comprises 'AB' and 'BA'(both of them) I print in out 'yes' and if only comprises 'ABA' or 'BAB'(overlap) the output is 'NO'. I wrote the following code but I receive error. the problem is in re.search() in if . how can I use correctly re.search for this code? Thanks in advance for your help
import re
str1=input()
if re.search('AB',str1):
if re.search('BA',str1):
if re.search('ABA'|'BAB',str1):
if re.search('ABBA'|'BAAB',str1):
print('YES')
print('NO')
print('YES')
else :
print('NO')
else:
print('NO')