Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Two regex with logical or

All the rows with either 'apple pie' or 'banana pie' in them.

import re

strings = [
    'apple pie',
    'banana pie',
    'apple'
]

for s in strings:
    #print(s)
    match1 = re.search(r'apple pie', s)
    match2 = re.search(r'banana pie', s)
    if match1 or match2:
        print('Matched in', s)

Output:

Matched in apple pie
Matched in banana pie