concept re module in category python

appears as: re module, The re module
Tiny Python Projects: Learn coding and testing with puzzles and games

This is an excerpt from Manning's book Tiny Python Projects: Learn coding and testing with puzzles and games.

  • Regular expressions provide a syntax for describing patterns of text with the re module. The re.sub() method will substitute found patterns with new text. The original text will be unchanged.
  • The re module has a function called re.split() that works similarly. I recommend you read help(re.split), as this is a very powerful and flexible function. Like re.match(), which we used in chapter 14, this function wants at least a pattern and a string. We can use re.split() with a comma to get the same output as str.split(), and, as before, the commas are missing from the result: