January 2019
Beginner
318 pages
8h 23m
English
This is one of the most important functions of the re module. The sub() is used for replacing the re pattern with the specified replacement. It will replace all the occurrences of the re pattern with the replacement string. The syntax is as follows:
re.sub(pattern, repl_str, string, count=0)
Now we are going to create a re_sub.py script and write the following content in it:
import restr_line = 'Peter Piper picked a peck of pickled peppers. How many pickled peppers did Peter Piper pick?'print("Original: ", str_line)p = re.sub('Peter', ...Read now
Unlock full access