in [ ] out[ ]in [ ]text[ start(): end()out[ ]'dave@google comregex match returns noneas it only will match if the pattern occurs at the start of the stringin [ ]print regex match(textnone relatedlysub will return new string with occurrences of the pattern replaced by the new stringin [ ]print regex sub('redacted'textdave redacted steve redacted rob redacted ryan redacted suppose you wanted to find email addresses and simultaneously segment each address into its componentsusernamedomain nameand domain suffix to do thisput parentheses around the parts of the pattern to segmentin [ ]pattern '([ - - %+-]+)@([ - - -]+)([ - ]{ , })in [ ]regex re compile(patternflags=re ignorecasea match object produced by this modified regex returns tuple of the pattern components with its groups methodin [ ] regex match('wesm@bright net'in [ ] groups(out[ ]('wesm''bright''net'findall returns list of tuples when the pattern has groupsin [ ]regex findall(textout[ ][('dave''google''com')('steve''gmail''com')('rob''gmail''com')('ryan''yahoo''com')sub also has access to groups in each match using special symbols like \ \ etc in [ ]print regex sub( 'username\ domain\ suffix\ 'textdave usernamedavedomaingooglesuffixcom steve usernamestevedomaingmailsuffixcom rob usernamerobdomaingmailsuffixcom ryan usernameryandomainyahoosuffixcom string manipulation www it-ebooks info