Python string supports pattern-based text processing.
Python module re has calls for searching, splitting, and replacement:
import re match = re.match('Hello[ \t]*(.*)world', 'Hello Python world') print( match.group(1) )
Here, we search for a substring that
If such a substring is found, portions of the substring matched by parts of the pattern are available as groups.
The following pattern picks out three groups separated by slashes, and is similar to splitting by an alternatives pattern:
import re match = re.match('[/:](.*)[/:](.*)[/:](.*)', '/usr/home:lumberjack') print( match.groups() ) print( re.split('[/:]', '/usr/home/lumberjack') )