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

Quantifiers on character classes

import re

strings = (
    "-a-",
    "-b-",
    "-x-",
    "-aa-",
    "-ab-",
    "--",
)

for line in strings:
    match = re.search(r'-[abc]-', line)
    if match:
        print(line)
print('=========================')

for line in strings:
    match = re.search(r'-[abc]+-', line)
    if match:
        print(line)
print('=========================')

for line in strings:
    match = re.search(r'-[abc]*-', line)
    if match:
        print(line)