User:Cristinac/RegEx

From XPUB & Lens-Based wiki
< User:Cristinac
Revision as of 21:37, 16 June 2015 by Cristinac (talk | contribs) (Created page with "<source lang="python"> import sys, re word = "yes" print ("this is the word:", word) while True: line = sys.stdin.readline() if line =='': break if line == word: pri...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
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