substring group (split treats groups specially)import re re split('--''aaa--bbb--ccc'['aaa''bbb''ccc're sub('--'''aaa--bbb--ccc''aaa bbb cccsingle string case re split('--|==''aaa--bbb==ccc'['aaa''bbb''ccc're sub('--|=='''aaa--bbb==ccc''aaa bbb cccsplit on -or =replace -or =re split('[-=]''aaa-bbb=ccc'['aaa''bbb''ccc'single char alternative re split('(--)|(==)''aaa--bbb==ccc'['aaa''--'none'bbb'none'==''ccc're split('(?:--)|(?:==)''aaa--bbb==ccc'['aaa''bbb''ccc'split includes groups expr partnot group similarlysplits can extract simple substrings for fixed delimitersbut patterns can also handle surrounding context like bracketsmark parts as optionalignore whitespaceand more in the next tests \smeans zero or more whitespace characters ( character class)\smeans one or more of the same/matches an optional slash[ -zis any lowercase letter ( range);*?means saved substring of zero or more of any character again--but only as many as needed to match the rest of the pattern (nongreedily)and the groups method is used to fetch the substrings matched by the parenthesized subpatterns all at once'spam/ham/eggssplit('/'['spam''ham''eggs're match('*)/*)/*)''spam/ham/eggs'groups(('spam''ham''eggs're match('//''//'groups(('spam''ham''eggs're match('\ */?/?'('spam''ham''eggs'/'groups('hello pattern world!split(['hello''pattern''world!'re match('hello\ *([ - ]*)\ +*?)\ *!''hellopattern ('pattern''world'world !'groups(in factthere' more than one way to match the findall method provides generality that leaves string objects in the dust--it locates all occurrences of pattern and returns all the substrings it matched (or list of tuples for multiple groupsthe search method is similar but stops at the first match--it' like match plus an initial forward scan in the followingstring object finds locate just one specific stringbut patterns can be used to regular expression pattern matching