User:Cristinac/RegEx

From XPUB & Lens-Based wiki
import sys, re

word = "yes"
print ("this is the word:", word)

while True:
	line = sys.stdin.readline()

	if line =='':
		break
	if line == word:
		print line
	line = re.sub(r"\bI\b","_you", line, flags=re.I)
	line = re.sub(r"\byou\b","_I", line, flags=re.I)
	line = re.sub(r"_I","I", line, flags=re.I)
	line = re.sub(r"_you","you", line, flags=re.I)


	print line