# Python Regular Expressions - [Documentation](#documentation) - [Match function](#match-function) - [Sub function](#sub-function) - [Search function](#search-function) ## Documentation * https://docs.python.org/3/library/re.html * https://www.regular-expressions.info/python.html ## Match function When matching, Gam uses the match function which always looks for a match at the beginning of a string. * "^Foo Bar$" - match the entire string "Foo Bar" * "Foo Bar" - match a string that starts with "Foo Bar" * ".*Foo Bar" - match a string that contains "Foo Bar" * ".*Foo Bar$" - match a string that ends with "Foo Bar" Select Aliases to display ``` gam print aliases [todrive *] [aliasmatchpattern ] ``` Collections ``` matchfield|skipfield keypattern ``` Display Classroom courses based on owner's email address ``` gam print courses [todrive *] [owneremailmatchpattern ] ``` Clear Contacts based on email address ``` gam clear contacts emailmatchpattern emailclearpattern ``` Display Contacts based on email address ``` gam print contacts emailmatchpattern ``` Delete Gmail labels based on label names ``` gam delete labels regex: ``` Display Gmail messages based on label names ``` gam print|show messages|threads [labelmatchpattern ``` Display Gmail messages based on sender email address ``` gam print|show messages|threads [sendermatchpattern ] |regex: ``` Display Gmail messages based on attachment names ``` gam print|show messages|threads [showattachments [attachmentnamepattern ]] ``` Save Gmail message attachments based on attachment names ``` gam show messages|threads [saveattachments [attachmentnamepattern ]] ``` Select Groups to display and which members to display ``` gam print groups [emailmatchpattern [not] ] [namematchpattern [not] ] [descriptionmatchpattern [not] ] [memberemaildisplaypattern|memberemailskippattern ] ``` Select Groups to display membership and which members to display ``` gam print group-members [emailmatchpattern [not] ] [namematchpattern [not] ] [descriptionmatchpattern [not] ] [memberemaildisplaypattern|memberemailskippattern ] ``` Manage Group membership ``` gam update group|groups clear [member] [manager] [owner] [emailclearpattern|emailretainpattern ] ``` Select User aliases to display ``` gam print users [aliasmatchpattern ] ``` Display Drive file information based on file names ``` gam print|show filecounts [filenamematchpattern ] gam print filelist [filenamematchpattern ] gam print|show filetree [filenamematchpattern ] ``` Update Drive file name based on a pattern ``` gam update drivefile (replacefilename )* ``` Select Vault exports to download ``` gam download vaultexport matter [bucketmatchpattern ] [objectmatchpattern ] ``` ## Sub function When substituting, Gam uses the sub function which looks for a match anywhere in a string. * "^Foo Bar$"` - match the entire string "Foo Bar" * "^Foo Bar"` - match a string that starts with "Foo Bar" * "Foo Bar"` - match a string that contains "Foo Bar" * "Foo Bar$"` - match a string that ends with "Foo Bar" Collections ``` keypattern keyvalue ``` Updating Calendar event descriptions uses the search function which looks for a match anywhere in a string. ``` gam calendars update events [] replacedescription gam update events [] replacedescription ``` Updating Drive file names uses the search function which looks for a match anywhere in a string. ``` gam update drivefile replacefilename replacefilename "^(.+) (.+)$" "\2 \1" - swap the two words separated by space, e.g. "Foo Bar" becomes "Bar Foo" ``` Updating Gmail label names uses the search function which looks for a match anywhere in a string. ``` gam update label search replace search "^Foo Bar$" replace "Doodle" - replace the entire string "Foo Bar" with "Doodle" ``` Updating User primary email addresses uses the search function which looks for a match anywhere in a string. ``` gam update user updateprimaryemail updateprimaryemail "^(.).*_(.+)@(.+)$" <\1\2@\3> - replace "first_last@domain.com" with "flast@domain.com" ``` ## Search function When searching, Gam uses the search function which always looks for a match anywhere in a string. * "^Foo Bar$"` - match the entire string "Foo Bar" * "^Foo Bar"` - match a string that starts with "Foo Bar" * "Foo Bar"` - match a string that contains "Foo Bar" * "Foo Bar$"` - match a string that ends with "Foo Bar" CSV input and output row filtering use the search function which looks for a match anywhere in a string. ``` :: = ::= [(any|all):]regex:| [(any|all):]regexcs:| [(any|all):]notregex:| [(any|all):]notregexcs: ``` Calendar event matchfields use the search function which looks for a match anywhere in a string. ``` ::= (matchfield attendees )| (matchfield attendeespattern )| (matchfield attendeesstatus [] [] )| (matchfield creatoremail )| (matchfield creatorname )| (matchfield description )| (matchfield location )| (matchfield organizeremail )| (matchfield organizername )| (matchfield status )| (matchfield summary )| (matchfield transparency )| (matchfield visibility ) ::= (+ *) ``` Updating user primary email addresses uses the search function which looks for a match anywhere in a string. ``` gam update user * updateprimaryemail ```