selection sets print(re search(* [de][ - ][^ -ze] \ ?"abcdefg\ "start()alternativesr | means or print(re search("( | )( | )( | ) "aycd "start()test each char print(re search("(?: | )(?: | )(?: | ) "aycd "start()samenot saved print(re search(" |xb|yc|zd"aycd "start()matches just aprint(re search("( |xb|yc|zd)ycd"aycd "start()just first char word boundaries print(re search( "\babcd"abcd "start()print(re search( "abcd\ "abcd "start()\ means word boundary use rto escape '\notice again that there are different ways to kick off match with reby calling module search functions and by making compiled pattern objects in either eventyou can hang on to the resulting match object or not all the print call statements in this script show result of --the offset where the pattern was found in the string in the first testfor examplea matches the abcd at offset in the search string ( after the first xx) :\pp \langpython re-basic py more omitted nextin example - parts of the pattern strings enclosed in parentheses delimit groupsthe parts of the string they matched are available after the match example - pp \lang\re-groups py ""groupsextract substrings matched by res in '()parts groups are denoted by positionbut (?prcan also name them ""import re patt re compile(" ) ) )"saves substrings mobj patt match(" "each '()is group print(mobj group( )mobj group( )mobj group( )group(gives substring patt re compile(" *) *) *)"mobj patt match(" "print(mobj groups()saves substrings groups(gives all groups print(re search("( | )( | )( | ) "aycd "groups()print(re search("(?pa| )(?pb| )(?pc| ) "aycd "groupdict()patt re compile( "[\ ]*#\ *define\ *([ - - ]*)\ **)"mobj patt search(define spam "parts of #define print(mobj groups()\ is whitespace in the first test herefor instancethe three groups each match single characterbut they retain the character matchedcalling group pulls out the character matched text and language