# regex.py by Bill Weinman [http://bw.org/]
# This is an exercise file from Python 3 Essential Training on lynda.com
# Copyright 2010 The BearHeart Gorup, LLC
import re
def main():
fh = open('raven.txt')
for line in fh:
if re.search('(Len|Neverm)ore', line):
print(line, end='')
if __name__ == "__main__": main()
#!/usr/bin/python3
# regex.py by Bill Weinman [http://bw.org/]
# This is an exercise file from Python 3 Essential Training on lynda.com
# Copyright 2010 The BearHeart Gorup, LLC
import re
def main():
fh = open('raven.txt')
for line in fh:
print(re.sub('(Len|Neverm)ore','###', line),end=' ')
if __name__ == "__main__": main()
------預編譯
#!/usr/bin/python3
# regex.py by Bill Weinman [http://bw.org/]
# This is an exercise file from Python 3 Essential Training on lynda.com
# Copyright 2010 The BearHeart Gorup, LLC
import re
def main():
fh = open('raven.txt')
pattern=re.compile('(Len|Neverm)ore')
for line in fh:
if re.search(pattern, line):
print(pattern.sub('###',line), end='')
if __name__ == "__main__": main()