import re

s = 'F6[ab]\nF3[ab]'
n = 'F6[ab]' # <= want to keep this in my string but want to change 'ab' in the new line
k = 'ab' # <= do not want to keep this in my string
c = '1' # <= change 'ab' -> '1'

print (re.sub(r'(' + re.escape(n) + rf')|\b{k}\b',
	lambda m: m.group(1) if m.group(1) else c, s))