the character is called pipe you can use it anywhere you want to match one of many expressions for examplethe regular expression 'batman|tina feywill match either 'batmanor 'tina feywhen both batman and tina fey occur in the searched stringthe first occurrence of matching text will be returned as the match object enter the following into the interactive shellheroregex re compile ( 'batman|tina fey'mo heroregex search('batman and tina fey'mo group('batmanmo heroregex search('tina fey and batman'mo group('tina feynote you can find all matching occurrences with the findall(method that' discussed in "the findall(methodon page you can also use the pipe to match one of several patterns as part of your regex for examplesay you wanted to match any of the strings 'batman''batmobile''batcopter'and 'batbatsince all these strings start with batit would be nice if you could specify that prefix only once this can be done with parentheses enter the following into the interactive shellbatregex re compile( 'bat(man|mobile|copter|bat)'mo batregex search('batmobile lost wheel'mo group('batmobilemo group( 'mobilethe method call mo group(returns the full matched text 'batmobile'while mo group( returns just the part of the matched text inside the first parentheses group'mobileby using the pipe character and grouping parenthesesyou can specify several alternative patterns you would like your regex to match if you need to match an actual pipe characterescape it with backslashlike \optional matching with the question mark sometimes there is pattern that you want to match only optionally that isthe regex should find match regardless of whether that bit of text is there the character flags the group that precedes it as an optional part of the pattern for exampleenter the following into the interactive shellbatregex re compile( 'bat(wo)?man'mo batregex search('the adventures of batman'