iNTERFACEWARE Products Manual > Learning Center > Learning Python > Working With Strings > Pattern Matching in Strings > Substitution Using Pattern Matching |
|
Looking for Iguana v.5 or v.6? Learn More or see the Help Center.
The re module includes the sub() function, which enables you to find any substring matching a specified pattern and replace it with a substring of your choice. For example, the following code replaces all occurrences of one or more consecutive whitespace characters with a single space:
To specify an upper limit on the number of substitutions to perform, supply a count as the fourth parameter to sub():
|