6.3. Regex Syntax Class
[abc]
- Enumeration[a-z]
- Range
6.3.1. SetUp
>>> import re
6.3.2. Enumeration
[abc]
- letter a or b or c
>>> TEXT = 'Email from Mark Watney <mwatney@nasa.gov> received on: Sun, Jan 2nd, 2000 at 12:00 AM'
Enumerations provide compact and more readable syntax for longer alternatives:
>>> re.findall(r'[abcd]', TEXT)
['a', 'a', 'a', 'a', 'a', 'a', 'c', 'd', 'a', 'd', 'a']
>>>
>>> re.findall(r'[123]', TEXT)
['2', '2', '1', '2']
It will work for both numbers, characters or any other object:
>>> re.findall(r'[abcd123]', TEXT)
['a', 'a', 'a', 'a', 'a', 'a', 'c', 'd', 'a', '2', 'd', '2', 'a', '1', '2']
Examples:
>>> re.findall(r'[a-z]', TEXT)
['m', 'a', 'i', 'l', 'f', 'r', 'o', 'm', 'a', 'r', 'k', 'a', 't',
'n', 'e', 'y', 'm', 'w', 'a', 't', 'n', 'e', 'y', 'n', 'a', 's',
'a', 'g', 'o', 'v', 'r', 'e', 'c', 'e', 'i', 'v', 'e', 'd', 'o',
'n', 'u', 'n', 'a', 'n', 'n', 'd', 'a', 't']
>>>
>>> re.findall(r'[az-]', TEXT)
['a', 'a', 'a', 'a', 'a', 'a', 'a', 'a']
>>> re.findall(r'[A-z]', TEXT)
['E', 'm', 'a', 'i', 'l', 'f', 'r', 'o', 'm', 'M', 'a', 'r', 'k',
'W', 'a', 't', 'n', 'e', 'y', 'm', 'w', 'a', 't', 'n', 'e', 'y',
'n', 'a', 's', 'a', 'g', 'o', 'v', 'r', 'e', 'c', 'e', 'i', 'v',
'e', 'd', 'o', 'n', 'S', 'u', 'n', 'J', 'a', 'n', 'n', 'd', 'a',
't', 'A', 'M']
>>>
>>> re.findall(r'[a-Z]', TEXT)
Traceback (most recent call last):
re.PatternError: bad character range a-Z at position 1
>>>
>>> re.findall(r'[z-a]', TEXT)
Traceback (most recent call last):
re.PatternError: bad character range z-a at position 1
Use Cases:
>>> re.findall(r'[aeiouy]', TEXT)
['a', 'i', 'o', 'a', 'a', 'e', 'y', 'a', 'e', 'y', 'a', 'a', 'o',
'e', 'e', 'i', 'e', 'o', 'u', 'a', 'a']
>>>
>>> re.findall(r'a|e|i|o|u|y', TEXT)
['a', 'i', 'o', 'a', 'a', 'e', 'y', 'a', 'e', 'y', 'a', 'a', 'o',
'e', 'e', 'i', 'e', 'o', 'u', 'a', 'a']
6.3.3. Range
[a-z]
- any lowercase ASCII letter from a to z[A-Z]
- any uppercase ASCII letter from A to Z[0-9]
- any digit from 0 to 9[a-zA-Z]
- any ASCII letter from: a to z or from A to Z[A-z]
- any ASCII letter from: a to z or from A to Z[a-zA-Z0-9]
- any ASCII letter from a to z or from A to Z or digit from 0 to 9
>>> TEXT = 'Email from Mark Watney <mwatney@nasa.gov> received on: Sun, Jan 2nd, 2000 at 12:00 AM'
Ranges provide even more readable and convenient way os specifying particular characters to match. It is very useful to define ranges of numbers or letters this way:
>>> re.findall(r'[a-z]', TEXT)
['m', 'a', 'i', 'l', 'f', 'r', 'o', 'm', 'a', 'r', 'k', 'a', 't',
'n', 'e', 'y', 'm', 'w', 'a', 't', 'n', 'e', 'y', 'n', 'a', 's',
'a', 'g', 'o', 'v', 'r', 'e', 'c', 'e', 'i', 'v', 'e', 'd', 'o',
'n', 'u', 'n', 'a', 'n', 'n', 'd', 'a', 't']
>>>
>>> re.findall(r'[A-Z]', TEXT)
['E', 'M', 'W', 'S', 'J', 'A', 'M']
>>>
>>> re.findall(r'[0-9]', TEXT)
['2', '2', '0', '0', '0', '1', '2', '0', '0']
Note, that regular expressions are case sensitive (unless re.IGNORECASE
flag is present. More information in Syntax Flags). You can also join
ranges to create even broader matches:
>>> re.findall(r'[a-zA-Z]', TEXT)
['E', 'm', 'a', 'i', 'l', 'f', 'r', 'o', 'm', 'M', 'a', 'r', 'k',
'W', 'a', 't', 'n', 'e', 'y', 'm', 'w', 'a', 't', 'n', 'e', 'y',
'n', 'a', 's', 'a', 'g', 'o', 'v', 'r', 'e', 'c', 'e', 'i', 'v',
'e', 'd', 'o', 'n', 'S', 'u', 'n', 'J', 'a', 'n', 'n', 'd', 'a',
't', 'A', 'M']
>>>
>>> re.findall(r'[a-zA-Z0-9]', TEXT)
['E', 'm', 'a', 'i', 'l', 'f', 'r', 'o', 'm', 'M', 'a', 'r', 'k',
'W', 'a', 't', 'n', 'e', 'y', 'm', 'w', 'a', 't', 'n', 'e', 'y',
'n', 'a', 's', 'a', 'g', 'o', 'v', 'r', 'e', 'c', 'e', 'i', 'v',
'e', 'd', 'o', 'n', 'S', 'u', 'n', 'J', 'a', 'n', '2', 'n', 'd',
'2', '0', '0', '0', 'a', 't', '1', '2', '0', '0', 'A', 'M']
Ranges are ordered in ASCII table order (more information in Locale
Encoding). Because uppercase letters are before lowercase letters (has
lower indexes), you can define range from Z-a
, but the opposite is not
true:
>>> re.findall(r'[Z-a]', TEXT)
['a', 'a', 'a', 'a', 'a', 'a', 'a', 'a']
>>> re.findall(r'[a-Z]', TEXT)
Traceback (most recent call last):
re.PatternError: bad character range a-Z at position 1
The last example can work in some other languages due to the different implementation of the algorithm or PCRE standard. More information in Syntax Extensions.
Mind that ranges not necessarily need to be from a-z. It could be any alphabetic or numeric range:
>>> re.findall(r'[2-7]', TEXT)
['2', '2', '2']
>>>
>>> re.findall(r'[C-Y]', TEXT)
['E', 'M', 'W', 'S', 'J', 'M']
>>>
>>> re.findall(r'[3-7C-Y]', TEXT)
['E', 'M', 'W', 'S', 'J', 'M']
6.3.4. Joining
[abc]|[123]
- Enumeration alternative - letter a, b or c or digit 1, 2 3[a-z]|[0-9]
- Range alternative - any lowercase ASCII letter from a to z or digit from 0 to 9
>>> TEXT = 'Email from Mark Watney <mwatney@nasa.gov> received on: Sun, Jan 2nd, 2000 at 12:00 AM'
Alternative enumerations syntax is as follows:
>>> re.findall(r'[abc]|[123]', TEXT)
['a', 'a', 'a', 'a', 'a', 'a', 'c', 'a', '2', '2', 'a', '1', '2']
The effect is identical to:
>>> re.findall(r'[abc123]', TEXT)
['a', 'a', 'a', 'a', 'a', 'a', 'c', 'a', '2', '2', 'a', '1', '2']
You can define alternative ranges to find:
>>> re.findall(r'[A-Z]|[0-9]', TEXT)
['E', 'M', 'W', 'S', 'J', '2', '2', '0', '0', '0', '1', '2', '0', '0', 'A', 'M']
The effect is identical to:
>>> re.findall(r'[A-Z0-9]', TEXT)
['E', 'M', 'W', 'S', 'J', '2', '2', '0', '0', '0', '1', '2', '0', '0', 'A', 'M']
6.3.5. Examples
[d-m]
- any lowercase letter from d to m[3-7]
- any digit from 3 to 7[xz2]
- x or z or 2[d-mK-P3-8]
- any lowercase letter from d to m or uppercase letter from K to P or digit from 3 to 8x|z|2
- x or z or 2d|x
- d or x[d-k]|[ABC]|[3-8]
- any lowercase letter from d to k or uppercase A,`B` or C or digit from 3 to 8
6.3.6. Case Study
import re
PHONE1 = '+48 (12) 345-6789'
PHONE2 = '+48 123 456 789'
# %%
phone1 = re.findall(r'[0-9]', PHONE1)
phone1
# ['4', '8', '1', '2', '3', '4', '5', '6', '7', '8', '9']
phone2 = re.findall(r'[0-9]', PHONE2)
phone2
# ['4', '8', '1', '2', '3', '4', '5', '6', '7', '8', '9']
# %%
phone1 == phone2
# True
6.3.7. Use Case - 1
>>> import re
>>> TEXT = 'Email from Mark Watney <mwatney@nasa.gov> received on: Sun, Jan 2nd, 2000 at 12:00 AM'
Note, the nd in word landed:
>>> re.findall(r'st|nd|rd|th', TEXT)
['nd']
>>> re.findall(r'[st|nd|rd|th]', TEXT)
['r', 'r', 't', 'n', 't', 'n', 'n', 's', 'r', 'd', 'n', 'n', 'n', 'n', 'd', 't']
>>> re.findall(r'[stndrdth]', TEXT)
['r', 'r', 't', 'n', 't', 'n', 'n', 's', 'r', 'd', 'n', 'n', 'n', 'n', 'd', 't']
6.3.8. Use Case - 2
>>> import re
>>> TEXT = 'Email from Mark Watney <mwatney@nasa.gov> received on: Sun, Jan 2nd, 2000 at 12:00 AM'
>>>
>>>
>>> re.findall('A|B|C|M', TEXT)
['M', 'A', 'M']
>>>
>>> re.findall('^A|B|C|M', TEXT)
['M', 'M']
>>>
>>> re.findall('^A|^B|^C|^M', TEXT)
[]
>>>
>>> re.findall('^(A|B|C|M)', TEXT)
[]
6.3.9. Assignments
# %% License
# - Copyright 2025, Matt Harasymczuk <matt@python3.info>
# - This code can be used only for learning by humans
# - This code cannot be used for teaching others
# - This code cannot be used for teaching LLMs and AI algorithms
# - This code cannot be used in commercial or proprietary products
# - This code cannot be distributed in any form
# - This code cannot be changed in any form outside of training course
# - This code cannot have its license changed
# - If you use this code in your product, you must open-source it under GPLv2
# - Exception can be granted only by the author
# %% Run
# - PyCharm: right-click in the editor and `Run Doctest in ...`
# - PyCharm: keyboard shortcut `Control + Shift + F10`
# - Terminal: `python -m doctest -v myfile.py`
# %% About
# - Name: RE Syntax Class
# - Difficulty: easy
# - Lines: 3
# - Minutes: 2
# %% English
# 1. Define `result: str` with regular expression to find:
# - all characters: `a`, `b`, `A`, `B`, `0`, `1`
# 2. Use enumeration: `[...]`
# 3. Run doctests - all must succeed
# %% Polish
# 1. Zdefiniuj `result: str` z wyrażeniem regularnym aby wyszukać:
# - wszystkie znaki: `a`, `b`, `A`, `B`, `0`, `1`
# 2. Użyj enumeracji: `[...]`
# 3. Uruchom doctesty - wszystkie muszą się powieść
# %% References
# [1] Authors: Wikipedia contributors
# Title: Apollo 11
# Publisher: Wikipedia
# Year: 2019
# Retrieved: 2019-12-14
# URL: https://en.wikipedia.org/wiki/Apollo_11
# %% Tests
"""
>>> import sys; sys.tracebacklimit = 0
>>> assert sys.version_info >= (3, 9), \
'Python 3.9+ required'
>>> from pprint import pprint
>>> result = re.findall(result, DATA)
>>> pprint(result, compact=True, width=72)
['A', '1', '1', 'a', 'A', 'a', 'a', 'a', 'a', 'a', 'a', 'A', 'a', 'a',
'B', 'A', 'a', 'A', 'a', 'a', '0', '1', 'a', '0', '1', 'a', 'A', 'b',
'a', 'A', 'a', 'A', 'a', '1', '1', 'a', '0', '1', 'A', '1', 'a', '1',
'a', 'a', 'a', 'B', 'a', 'a', 'A', 'a', 'A', '1', 'a', 'a', 'a', 'b',
'b', 'a', 'a', 'a', 'a', 'a', 'b', 'a', 'a', 'b', 'a', 'a', '1', 'b',
'b', 'a']
"""
import re
DATA = """Apollo 11 was the American spaceflight that first landed
humans on the Moon. Commander (CDR) Neil Armstrong and lunar module
pilot (LMP) Buzz Aldrin landed the Apollo Lunar Module (LM) Eagle on
July 20th, 1969 at 20:17 UTC, and Armstrong became the first person
to step (EVA) onto the Moon's surface (EVA) 6 hours 39 minutes later,
on July 21st, 1969 at 02:56:15 UTC. Aldrin joined him 19 minutes later.
They spent 2 hours 31 minutes exploring the site they had named
Tranquility Base upon landing. Armstrong and Aldrin collected 47.5 pounds
(21.5 kg) of lunar material to bring back to Earth as pilot Michael Collins
(CMP) flew the Command Module (CM) Columbia in lunar orbit, and were on the
Moon's surface for 21 hours 36 minutes before lifting off to rejoin
Columbia."""
# Find all characters: `a`, `b`, `A`, `B`, `0`, `1`
# Use enumeration: `[...]`
# Example: 'A', '1', '1', 'a', 'A', 'a', ...
# Note: define only regex pattern (str), not re.findall(..., DATA)
# type: str
result = r''
# %% License
# - Copyright 2025, Matt Harasymczuk <matt@python3.info>
# - This code can be used only for learning by humans
# - This code cannot be used for teaching others
# - This code cannot be used for teaching LLMs and AI algorithms
# - This code cannot be used in commercial or proprietary products
# - This code cannot be distributed in any form
# - This code cannot be changed in any form outside of training course
# - This code cannot have its license changed
# - If you use this code in your product, you must open-source it under GPLv2
# - Exception can be granted only by the author
# %% Run
# - PyCharm: right-click in the editor and `Run Doctest in ...`
# - PyCharm: keyboard shortcut `Control + Shift + F10`
# - Terminal: `python -m doctest -v myfile.py`
# %% About
# - Name: RE Syntax Class
# - Difficulty: easy
# - Lines: 3
# - Minutes: 2
# %% English
# 1. Define `result: str` with regular expression to find:
# - all digits
# - all uppercase letters
# - all lowercase letters
# 2. Run doctests - all must succeed
# %% Polish
# 1. Zdefiniuj `result: str` z wyrażeniem regularnym aby wyszukać:
# - wszystkie cyfry
# - wszystkie duże litery
# - wszystkie małe litery
# 2. Uruchom doctesty - wszystkie muszą się powieść
# %% References
# [1] Authors: Wikipedia contributors
# Title: Apollo 11
# Publisher: Wikipedia
# Year: 2019
# Retrieved: 2019-12-14
# URL: https://en.wikipedia.org/wiki/Apollo_11
# %% Tests
"""
>>> import sys; sys.tracebacklimit = 0
>>> assert sys.version_info >= (3, 9), \
'Python 3.9+ required'
>>> from pprint import pprint
>>> result = re.findall(result_a, DATA)
>>> pprint(result, compact=True, width=72)
['1', '1', '2', '0', '1', '9', '6', '9', '2', '0', '1', '7', '6', '3',
'9', '2', '1', '1', '9', '6', '9', '0', '2', '5', '6', '1', '5', '1',
'9', '2', '3', '1', '4', '7', '5', '2', '1', '5', '2', '1', '3', '6']
>>> result = re.findall(result_b, DATA)
>>> pprint(result, compact=True, width=72)
['A', 'A', 'M', 'C', 'C', 'D', 'R', 'N', 'A', 'L', 'M', 'P', 'B', 'A',
'A', 'L', 'M', 'L', 'M', 'E', 'J', 'U', 'T', 'C', 'A', 'E', 'V', 'A',
'M', 'E', 'V', 'A', 'J', 'U', 'T', 'C', 'A', 'T', 'T', 'B', 'A', 'A',
'E', 'M', 'C', 'C', 'M', 'P', 'C', 'M', 'C', 'M', 'C', 'M', 'C']
>>> result = re.findall(result_c, DATA)
>>> pprint(result, compact=True, width=72)
['p', 'o', 'l', 'l', 'o', 'w', 'a', 's', 't', 'h', 'e', 'm', 'e', 'r',
'i', 'c', 'a', 'n', 's', 'p', 'a', 'c', 'e', 'f', 'l', 'i', 'g', 'h',
't', 't', 'h', 'a', 't', 'f', 'i', 'r', 's', 't', 'l', 'a', 'n', 'd',
'e', 'd', 'h', 'u', 'm', 'a', 'n', 's', 'o', 'n', 't', 'h', 'e', 'o',
'o', 'n', 'o', 'm', 'm', 'a', 'n', 'd', 'e', 'r', 'e', 'i', 'l', 'r',
'm', 's', 't', 'r', 'o', 'n', 'g', 'a', 'n', 'd', 'l', 'u', 'n', 'a',
'r', 'm', 'o', 'd', 'u', 'l', 'e', 'p', 'i', 'l', 'o', 't', 'u', 'z',
'z', 'l', 'd', 'r', 'i', 'n', 'l', 'a', 'n', 'd', 'e', 'd', 't', 'h',
'e', 'p', 'o', 'l', 'l', 'o', 'u', 'n', 'a', 'r', 'o', 'd', 'u', 'l',
'e', 'a', 'g', 'l', 'e', 'o', 'n', 'u', 'l', 'y', 't', 'h', 'a', 't',
'a', 'n', 'd', 'r', 'm', 's', 't', 'r', 'o', 'n', 'g', 'b', 'e', 'c',
'a', 'm', 'e', 't', 'h', 'e', 'f', 'i', 'r', 's', 't', 'p', 'e', 'r',
's', 'o', 'n', 't', 'o', 's', 't', 'e', 'p', 'o', 'n', 't', 'o', 't',
'h', 'e', 'o', 'o', 'n', 's', 's', 'u', 'r', 'f', 'a', 'c', 'e', 'h',
'o', 'u', 'r', 's', 'm', 'i', 'n', 'u', 't', 'e', 's', 'l', 'a', 't',
'e', 'r', 'o', 'n', 'u', 'l', 'y', 's', 't', 'a', 't', 'l', 'd', 'r',
'i', 'n', 'j', 'o', 'i', 'n', 'e', 'd', 'h', 'i', 'm', 'm', 'i', 'n',
'u', 't', 'e', 's', 'l', 'a', 't', 'e', 'r', 'h', 'e', 'y', 's', 'p',
'e', 'n', 't', 'h', 'o', 'u', 'r', 's', 'm', 'i', 'n', 'u', 't', 'e',
's', 'e', 'x', 'p', 'l', 'o', 'r', 'i', 'n', 'g', 't', 'h', 'e', 's',
'i', 't', 'e', 't', 'h', 'e', 'y', 'h', 'a', 'd', 'n', 'a', 'm', 'e',
'd', 'r', 'a', 'n', 'q', 'u', 'i', 'l', 'i', 't', 'y', 'a', 's', 'e',
'u', 'p', 'o', 'n', 'l', 'a', 'n', 'd', 'i', 'n', 'g', 'r', 'm', 's',
't', 'r', 'o', 'n', 'g', 'a', 'n', 'd', 'l', 'd', 'r', 'i', 'n', 'c',
'o', 'l', 'l', 'e', 'c', 't', 'e', 'd', 'p', 'o', 'u', 'n', 'd', 's',
'k', 'g', 'o', 'f', 'l', 'u', 'n', 'a', 'r', 'm', 'a', 't', 'e', 'r',
'i', 'a', 'l', 't', 'o', 'b', 'r', 'i', 'n', 'g', 'b', 'a', 'c', 'k',
't', 'o', 'a', 'r', 't', 'h', 'a', 's', 'p', 'i', 'l', 'o', 't', 'i',
'c', 'h', 'a', 'e', 'l', 'o', 'l', 'l', 'i', 'n', 's', 'f', 'l', 'e',
'w', 't', 'h', 'e', 'o', 'm', 'm', 'a', 'n', 'd', 'o', 'd', 'u', 'l',
'e', 'o', 'l', 'u', 'm', 'b', 'i', 'a', 'i', 'n', 'l', 'u', 'n', 'a',
'r', 'o', 'r', 'b', 'i', 't', 'a', 'n', 'd', 'w', 'e', 'r', 'e', 'o',
'n', 't', 'h', 'e', 'o', 'o', 'n', 's', 's', 'u', 'r', 'f', 'a', 'c',
'e', 'f', 'o', 'r', 'h', 'o', 'u', 'r', 's', 'm', 'i', 'n', 'u', 't',
'e', 's', 'b', 'e', 'f', 'o', 'r', 'e', 'l', 'i', 'f', 't', 'i', 'n',
'g', 'o', 'f', 'f', 't', 'o', 'r', 'e', 'j', 'o', 'i', 'n', 'o', 'l',
'u', 'm', 'b', 'i', 'a']
"""
import re
DATA = """Apollo 11 was the American spaceflight that first landed
humans on the Moon. Commander (CDR) Neil Armstrong and lunar module
pilot (LMP) Buzz Aldrin landed the Apollo Lunar Module (LM) Eagle on
July 20th, 1969 at 20:17 UTC, and Armstrong became the first person
to step (EVA) onto the Moon's surface (EVA) 6 hours 39 minutes later,
on July 21st, 1969 at 02:56:15 UTC. Aldrin joined him 19 minutes later.
They spent 2 hours 31 minutes exploring the site they had named
Tranquility Base upon landing. Armstrong and Aldrin collected 47.5 pounds
(21.5 kg) of lunar material to bring back to Earth as pilot Michael Collins
(CMP) flew the Command Module (CM) Columbia in lunar orbit, and were on the
Moon's surface for 21 hours 36 minutes before lifting off to rejoin
Columbia."""
# Find all digits in text
# Example: '1', '1', '2', '0', '1', '9', '6', ...
# Note: define only regex pattern (str), not re.findall(..., DATA)
# type: str
result_a = r''
# Find all uppercase letters in text
# Example: 'A', 'A', 'M', 'C', 'C', 'D', 'R', ...
# Note: define only regex pattern (str), not re.findall(..., DATA)
# type: str
result_b = r''
# Find all lowercase letters in text
# Example: 'p', 'o', 'l', 'l', 'o', ...
# Note: define only regex pattern (str), not re.findall(..., DATA)
# type: str
result_c = r''
# %% License
# - Copyright 2025, Matt Harasymczuk <matt@python3.info>
# - This code can be used only for learning by humans
# - This code cannot be used for teaching others
# - This code cannot be used for teaching LLMs and AI algorithms
# - This code cannot be used in commercial or proprietary products
# - This code cannot be distributed in any form
# - This code cannot be changed in any form outside of training course
# - This code cannot have its license changed
# - If you use this code in your product, you must open-source it under GPLv2
# - Exception can be granted only by the author
# %% Run
# - PyCharm: right-click in the editor and `Run Doctest in ...`
# - PyCharm: keyboard shortcut `Control + Shift + F10`
# - Terminal: `python -m doctest -v myfile.py`
# %% About
# - Name: RE Syntax Class
# - Difficulty: easy
# - Lines: 3
# - Minutes: 2
# %% English
# 1. Define `result: str` with regular expression to find:
# - all lowercase and uppercase letters
# - all lowercase and uppercase letters and digits
# 2. Run doctests - all must succeed
# %% Polish
# 1. Zdefiniuj `result: str` z wyrażeniem regularnym aby wyszukać:
# - wszystkie małe i duże litery
# - wszystkie małe i duże litery oraz wszystkie cyfry
# 2. Uruchom doctesty - wszystkie muszą się powieść
# %% References
# [1] Authors: Wikipedia contributors
# Title: Apollo 11
# Publisher: Wikipedia
# Year: 2019
# Retrieved: 2019-12-14
# URL: https://en.wikipedia.org/wiki/Apollo_11
# %% Tests
"""
>>> import sys; sys.tracebacklimit = 0
>>> assert sys.version_info >= (3, 9), \
'Python 3.9+ required'
>>> from pprint import pprint
>>> result = re.findall(result_a, DATA)
>>> pprint(result, compact=True, width=72)
['A', 'p', 'o', 'l', 'l', 'o', 'w', 'a', 's', 't', 'h', 'e', 'A', 'm',
'e', 'r', 'i', 'c', 'a', 'n', 's', 'p', 'a', 'c', 'e', 'f', 'l', 'i',
'g', 'h', 't', 't', 'h', 'a', 't', 'f', 'i', 'r', 's', 't', 'l', 'a',
'n', 'd', 'e', 'd', 'h', 'u', 'm', 'a', 'n', 's', 'o', 'n', 't', 'h',
'e', 'M', 'o', 'o', 'n', 'C', 'o', 'm', 'm', 'a', 'n', 'd', 'e', 'r',
'C', 'D', 'R', 'N', 'e', 'i', 'l', 'A', 'r', 'm', 's', 't', 'r', 'o',
'n', 'g', 'a', 'n', 'd', 'l', 'u', 'n', 'a', 'r', 'm', 'o', 'd', 'u',
'l', 'e', 'p', 'i', 'l', 'o', 't', 'L', 'M', 'P', 'B', 'u', 'z', 'z',
'A', 'l', 'd', 'r', 'i', 'n', 'l', 'a', 'n', 'd', 'e', 'd', 't', 'h',
'e', 'A', 'p', 'o', 'l', 'l', 'o', 'L', 'u', 'n', 'a', 'r', 'M', 'o',
'd', 'u', 'l', 'e', 'L', 'M', 'E', 'a', 'g', 'l', 'e', 'o', 'n', 'J',
'u', 'l', 'y', 't', 'h', 'a', 't', 'U', 'T', 'C', 'a', 'n', 'd', 'A',
'r', 'm', 's', 't', 'r', 'o', 'n', 'g', 'b', 'e', 'c', 'a', 'm', 'e',
't', 'h', 'e', 'f', 'i', 'r', 's', 't', 'p', 'e', 'r', 's', 'o', 'n',
't', 'o', 's', 't', 'e', 'p', 'E', 'V', 'A', 'o', 'n', 't', 'o', 't',
'h', 'e', 'M', 'o', 'o', 'n', 's', 's', 'u', 'r', 'f', 'a', 'c', 'e',
'E', 'V', 'A', 'h', 'o', 'u', 'r', 's', 'm', 'i', 'n', 'u', 't', 'e',
's', 'l', 'a', 't', 'e', 'r', 'o', 'n', 'J', 'u', 'l', 'y', 's', 't',
'a', 't', 'U', 'T', 'C', 'A', 'l', 'd', 'r', 'i', 'n', 'j', 'o', 'i',
'n', 'e', 'd', 'h', 'i', 'm', 'm', 'i', 'n', 'u', 't', 'e', 's', 'l',
'a', 't', 'e', 'r', 'T', 'h', 'e', 'y', 's', 'p', 'e', 'n', 't', 'h',
'o', 'u', 'r', 's', 'm', 'i', 'n', 'u', 't', 'e', 's', 'e', 'x', 'p',
'l', 'o', 'r', 'i', 'n', 'g', 't', 'h', 'e', 's', 'i', 't', 'e', 't',
'h', 'e', 'y', 'h', 'a', 'd', 'n', 'a', 'm', 'e', 'd', 'T', 'r', 'a',
'n', 'q', 'u', 'i', 'l', 'i', 't', 'y', 'B', 'a', 's', 'e', 'u', 'p',
'o', 'n', 'l', 'a', 'n', 'd', 'i', 'n', 'g', 'A', 'r', 'm', 's', 't',
'r', 'o', 'n', 'g', 'a', 'n', 'd', 'A', 'l', 'd', 'r', 'i', 'n', 'c',
'o', 'l', 'l', 'e', 'c', 't', 'e', 'd', 'p', 'o', 'u', 'n', 'd', 's',
'k', 'g', 'o', 'f', 'l', 'u', 'n', 'a', 'r', 'm', 'a', 't', 'e', 'r',
'i', 'a', 'l', 't', 'o', 'b', 'r', 'i', 'n', 'g', 'b', 'a', 'c', 'k',
't', 'o', 'E', 'a', 'r', 't', 'h', 'a', 's', 'p', 'i', 'l', 'o', 't',
'M', 'i', 'c', 'h', 'a', 'e', 'l', 'C', 'o', 'l', 'l', 'i', 'n', 's',
'C', 'M', 'P', 'f', 'l', 'e', 'w', 't', 'h', 'e', 'C', 'o', 'm', 'm',
'a', 'n', 'd', 'M', 'o', 'd', 'u', 'l', 'e', 'C', 'M', 'C', 'o', 'l',
'u', 'm', 'b', 'i', 'a', 'i', 'n', 'l', 'u', 'n', 'a', 'r', 'o', 'r',
'b', 'i', 't', 'a', 'n', 'd', 'w', 'e', 'r', 'e', 'o', 'n', 't', 'h',
'e', 'M', 'o', 'o', 'n', 's', 's', 'u', 'r', 'f', 'a', 'c', 'e', 'f',
'o', 'r', 'h', 'o', 'u', 'r', 's', 'm', 'i', 'n', 'u', 't', 'e', 's',
'b', 'e', 'f', 'o', 'r', 'e', 'l', 'i', 'f', 't', 'i', 'n', 'g', 'o',
'f', 'f', 't', 'o', 'r', 'e', 'j', 'o', 'i', 'n', 'C', 'o', 'l', 'u',
'm', 'b', 'i', 'a']
>>> result = re.findall(result_b, DATA)
>>> pprint(result, compact=True, width=72)
['A', 'p', 'o', 'l', 'l', 'o', '1', '1', 'w', 'a', 's', 't', 'h', 'e',
'A', 'm', 'e', 'r', 'i', 'c', 'a', 'n', 's', 'p', 'a', 'c', 'e', 'f',
'l', 'i', 'g', 'h', 't', 't', 'h', 'a', 't', 'f', 'i', 'r', 's', 't',
'l', 'a', 'n', 'd', 'e', 'd', 'h', 'u', 'm', 'a', 'n', 's', 'o', 'n',
't', 'h', 'e', 'M', 'o', 'o', 'n', 'C', 'o', 'm', 'm', 'a', 'n', 'd',
'e', 'r', 'C', 'D', 'R', 'N', 'e', 'i', 'l', 'A', 'r', 'm', 's', 't',
'r', 'o', 'n', 'g', 'a', 'n', 'd', 'l', 'u', 'n', 'a', 'r', 'm', 'o',
'd', 'u', 'l', 'e', 'p', 'i', 'l', 'o', 't', 'L', 'M', 'P', 'B', 'u',
'z', 'z', 'A', 'l', 'd', 'r', 'i', 'n', 'l', 'a', 'n', 'd', 'e', 'd',
't', 'h', 'e', 'A', 'p', 'o', 'l', 'l', 'o', 'L', 'u', 'n', 'a', 'r',
'M', 'o', 'd', 'u', 'l', 'e', 'L', 'M', 'E', 'a', 'g', 'l', 'e', 'o',
'n', 'J', 'u', 'l', 'y', '2', '0', 't', 'h', '1', '9', '6', '9', 'a',
't', '2', '0', '1', '7', 'U', 'T', 'C', 'a', 'n', 'd', 'A', 'r', 'm',
's', 't', 'r', 'o', 'n', 'g', 'b', 'e', 'c', 'a', 'm', 'e', 't', 'h',
'e', 'f', 'i', 'r', 's', 't', 'p', 'e', 'r', 's', 'o', 'n', 't', 'o',
's', 't', 'e', 'p', 'E', 'V', 'A', 'o', 'n', 't', 'o', 't', 'h', 'e',
'M', 'o', 'o', 'n', 's', 's', 'u', 'r', 'f', 'a', 'c', 'e', 'E', 'V',
'A', '6', 'h', 'o', 'u', 'r', 's', '3', '9', 'm', 'i', 'n', 'u', 't',
'e', 's', 'l', 'a', 't', 'e', 'r', 'o', 'n', 'J', 'u', 'l', 'y', '2',
'1', 's', 't', '1', '9', '6', '9', 'a', 't', '0', '2', '5', '6', '1',
'5', 'U', 'T', 'C', 'A', 'l', 'd', 'r', 'i', 'n', 'j', 'o', 'i', 'n',
'e', 'd', 'h', 'i', 'm', '1', '9', 'm', 'i', 'n', 'u', 't', 'e', 's',
'l', 'a', 't', 'e', 'r', 'T', 'h', 'e', 'y', 's', 'p', 'e', 'n', 't',
'2', 'h', 'o', 'u', 'r', 's', '3', '1', 'm', 'i', 'n', 'u', 't', 'e',
's', 'e', 'x', 'p', 'l', 'o', 'r', 'i', 'n', 'g', 't', 'h', 'e', 's',
'i', 't', 'e', 't', 'h', 'e', 'y', 'h', 'a', 'd', 'n', 'a', 'm', 'e',
'd', 'T', 'r', 'a', 'n', 'q', 'u', 'i', 'l', 'i', 't', 'y', 'B', 'a',
's', 'e', 'u', 'p', 'o', 'n', 'l', 'a', 'n', 'd', 'i', 'n', 'g', 'A',
'r', 'm', 's', 't', 'r', 'o', 'n', 'g', 'a', 'n', 'd', 'A', 'l', 'd',
'r', 'i', 'n', 'c', 'o', 'l', 'l', 'e', 'c', 't', 'e', 'd', '4', '7',
'5', 'p', 'o', 'u', 'n', 'd', 's', '2', '1', '5', 'k', 'g', 'o', 'f',
'l', 'u', 'n', 'a', 'r', 'm', 'a', 't', 'e', 'r', 'i', 'a', 'l', 't',
'o', 'b', 'r', 'i', 'n', 'g', 'b', 'a', 'c', 'k', 't', 'o', 'E', 'a',
'r', 't', 'h', 'a', 's', 'p', 'i', 'l', 'o', 't', 'M', 'i', 'c', 'h',
'a', 'e', 'l', 'C', 'o', 'l', 'l', 'i', 'n', 's', 'C', 'M', 'P', 'f',
'l', 'e', 'w', 't', 'h', 'e', 'C', 'o', 'm', 'm', 'a', 'n', 'd', 'M',
'o', 'd', 'u', 'l', 'e', 'C', 'M', 'C', 'o', 'l', 'u', 'm', 'b', 'i',
'a', 'i', 'n', 'l', 'u', 'n', 'a', 'r', 'o', 'r', 'b', 'i', 't', 'a',
'n', 'd', 'w', 'e', 'r', 'e', 'o', 'n', 't', 'h', 'e', 'M', 'o', 'o',
'n', 's', 's', 'u', 'r', 'f', 'a', 'c', 'e', 'f', 'o', 'r', '2', '1',
'h', 'o', 'u', 'r', 's', '3', '6', 'm', 'i', 'n', 'u', 't', 'e', 's',
'b', 'e', 'f', 'o', 'r', 'e', 'l', 'i', 'f', 't', 'i', 'n', 'g', 'o',
'f', 'f', 't', 'o', 'r', 'e', 'j', 'o', 'i', 'n', 'C', 'o', 'l', 'u',
'm', 'b', 'i', 'a']
"""
import re
DATA = """Apollo 11 was the American spaceflight that first landed
humans on the Moon. Commander (CDR) Neil Armstrong and lunar module
pilot (LMP) Buzz Aldrin landed the Apollo Lunar Module (LM) Eagle on
July 20th, 1969 at 20:17 UTC, and Armstrong became the first person
to step (EVA) onto the Moon's surface (EVA) 6 hours 39 minutes later,
on July 21st, 1969 at 02:56:15 UTC. Aldrin joined him 19 minutes later.
They spent 2 hours 31 minutes exploring the site they had named
Tranquility Base upon landing. Armstrong and Aldrin collected 47.5 pounds
(21.5 kg) of lunar material to bring back to Earth as pilot Michael Collins
(CMP) flew the Command Module (CM) Columbia in lunar orbit, and were on the
Moon's surface for 21 hours 36 minutes before lifting off to rejoin
Columbia."""
# Find all lowercase and uppercase letters
# Example: 'a', 'A', 'b', 'B', 'c', 'C', ...
# Note: define only regex pattern (str), not re.findall(..., DATA)
# type: str
result_a = r''
# Find all lowercase and uppercase letters and digits
# Example: 'a', 'A', 'b', 'B', 'c', 'C', '1', '2', '3', ...
# Note: define only regex pattern (str), not re.findall(..., DATA)
# type: str
result_b = r''