<aside> 💡 Character class that offers choices from a set of character where we need the choice between some of regular expression. This is a logic “or” and that’s why the symbol for this construction is “|” symbol.

</aside>

Example

import re 
str = "Course location is Jakarta or Zurich!"
mo = re.search(r"location.*(London|Jakarta|Kuala Lumpur|Strasbourg)",str)
if mo: print(mo.group())
location is Jakarta

In this example, we examine whether one of the cities from Jakarta, London, KL, NY, or Strasbourg appear in string that is begun with a word “location”:

If we think of this example is kind of a bit artificial, there is another example. Let’s assume we want to filter our email. We want to find the correspondent (conversation) between us and our client. Next Regular expression will be useful for that:

<aside> 💡 fr"(^To:|^From:)(Tutor|MySkill)"

</aside>

This expression is suitable with all lines that is started with ‘To;’ or ‘From:’, it is followed with space and then with the beginning name ‘My’ or end name ‘My Skill’