split string by occurrences of pattern if capturing parentheses (()are used in the patternthe text of all groups in the pattern are also returned in the resulting list sub(patternreplstring [countflags]return the string obtained by replacing the (first countleftmost nonoverlapping occurrences of pattern ( string or pattern objectin string by repl (which may be string with backslash escapes that may back-reference matched groupor function that is passed single match object and returns the replacement stringsubn(patternreplstring [countflags]same as subbut returns tuple(new-stringnumber-of-substitutions-madeescape(stringreturn string with all nonalphanumeric characters backslashedsuch that they can be compiled as string literal compiled pattern objects at the next levelpattern objects provide similar attributesbut the pattern string is implied the re compile function in the previous section is useful to optimize patterns that may be matched more than once (compiled patterns match fasterpattern objects returned by re compile have these sorts of attributesmatch(string [pos[endpos]search(string [pos[endpos]findall(string [pos [endpos]]finditer(string [pos [endpos]]split(string [maxsplit]sub(replstring [count]subn(replstring [count]these are the same as the re module functionsbut the pattern is impliedand pos and endpos give start/end string indexes for the match match objects finallywhen match or search function or method is successfulyou get back match object (none comes back on failed matchesmatch objects export set of attributes of their ownincludinggroup(ggroup( return the substring that matched parenthesized group (or groupsin the pattern accept group numbers or names group numbers start at group is the entire string matched by the pattern returns tuple when passed multiple group numbersand group number defaults to if omitted text and language