Unit 10Pattern Matching with Regular Expressions

Regular expressions are a powerful mechanism for searching, splitting, and replacing strings based on pattern matching. The module re provides a pattern description language and a collection of functions for matching, searching, splitting, and replacing strings.

From the Python point of view, a regular expression is simply a string containing the description of a pattern. You can make pattern matching much more efficient if you compile a regular expression that you plan to use more than once:

 compiledPattern = re.compile(pattern, flags=0)

Compilation substantially improves pattern matching time but doesn’t affect correctness. If you want, you can specify pattern matching flags, either at the ...

Get Data Science Essentials in Python now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.