6.6. Regex Syntax CharacterClass

  • Character Classes specifies what to find

6.6.1. SetUp

>>> import re

6.6.2. Numeric

  • \d - digit

  • \D - anything but digit

SetUp:

>>> TEXT = 'Email from Mark Watney <mwatney@nasa.gov> received on: Sun, Jan 2nd, 2000 at 12:00 AM'

Digit:

>>> re.findall(r'[0-9]', TEXT)
['2', '2', '0', '0', '0', '1', '2', '0', '0']
>>>
>>> re.findall(r'\d', TEXT)
['2', '2', '0', '0', '0', '1', '2', '0', '0']

Anything but digit:

>>> re.findall(r'[^0-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', ' ', 'n', 'd', ',', ' ', ' ', 'a',
 't', ' ', ':', ' ', 'A', 'M']
>>>
>>> re.findall(r'\D', 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']

6.6.3. Whitespaces

  • \s - whitespace (space, tab, newline, non-breaking space)

  • \S - anything but whitespace

  • \n - newline

  • \r\n - windows newline

  • \r - carriage return

  • \b - backspace

  • \t - tab

  • \v - vertical space

  • \f - form feed

SetUp:

>>> TEXT = 'Email from Mark Watney <mwatney@nasa.gov> received on: Sun, Jan 2nd, 2000 at 12:00 AM'

Whitespace:

>>> re.findall(r'[ \t\n\r\v\f\b]', TEXT)
[' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ']
>>>
>>> re.findall(r'\s', TEXT)
[' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ']

Anything but whitespace:

>>> re.findall(r'[^ \t\n\r\v\f\b]', 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']
>>>
>>> re.findall(r'\S', 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']

6.6.4. Word Boundary

  • Matches the empty string, but only at the beginning or end of a word

  • \b - word boundary

  • \B - anything but word boundary

Examples:

  • \babc\b - performs a "whole words only" search

  • \Babc\B - pattern is fully surrounded by word characters

>>> TEXT = 'Email from Mark Watney <mwatney@nasa.gov> received on: Sun, Jan 2nd, 2000 at 12:00 AM'
>>> re.findall(r'[a-z][a-z]', TEXT)  
['ma', 'il', 'fr', 'om', 'ar', 'at', 'ne', 'mw', 'at', 'ne', 'na',
 'sa', 'go', 're', 'ce', 'iv', 'ed', 'on', 'un', 'an', 'nd', 'at']
>>> re.findall(r' [a-z][a-z] ', TEXT)  
[' at ']

However still on is missing, because it has colon (no space) at the end:

>>> re.findall(r'\b[a-z][a-z]\b', TEXT)
['on', 'at']
>>> re.findall(r'\b[a-z][a-z]\B', TEXT)
['fr', 'mw', 'na', 'go', 're']
>>> re.findall(r'\B[a-z][a-z]\b', TEXT)
['il', 'om', 'rk', 'ey', 'ey', 'sa', 'ov', 'ed', 'un', 'an', 'nd']

Without raw-string:

>>> re.findall('\b[a-z][a-z]\b', TEXT)
[]

6.6.5. Word Character

  • \w - any unicode alphabet character: lowercase, uppercase, numbers, underscores, national characters

  • \W - anything but any unicode alphabet character (i.e. whitespace, dots, comas, dashes)

  • lowercase letters

  • uppercase letters

  • digits

  • underscores (_)

  • national characters: ąćęłńóśżź... and ĄĆĘŁŃÓŚŻŹ... (uppercase and lowercase)

Valid characters are the same as allowed in variable/modules names in Python:

>>> imie = 'Mark'
>>> IMIE = 'Mark'
>>> imię = 'Mark'
>>> imię1 = 'Mark'
>>> Imię_1 = 'Mark'

Example:

>>> TEXT = 'Email from Mark Watney <mwatney@nasa.gov> received on: Sun, Jan 2nd, 2000 at 12:00 AM'
>>> re.findall(r'\w', 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']
>>> re.findall(r'\W', TEXT)  
[' ', ' ', ' ', ' ', '<', '@', '.', '>', ' ', ' ', ':', ' ', ',',
 ' ', ' ', ',', ' ', ' ', ' ', ':', ' ']

Mind, that following code gives similar output to \w but it is not completely true. \w would extract also unicode characters while this [a-zA-Z0-9] will not.

>>> 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']

Example:

>>> text = 'cześć'
>>>
>>> re.findall(r'[a-z]', text)
['c', 'z', 'e']
>>>
>>> re.findall(r'\w', text)
['c', 'z', 'e', 'ś', 'ć']

With flag re.UNICODE Python will also match national characters (uppercase and lowercase) while using \w and \W. Setting flag re.ASCII can turn off this behavior, and narrow down matches to ASCII characters which can potentially improve speed, in texts where national characters are not used. Flag re.UNICODE is set by default:

>>> re.findall(r'\w', text)
['c', 'z', 'e', 'ś', 'ć']
>>>
>>> re.findall(r'\w', text, flags=re.UNICODE)
['c', 'z', 'e', 'ś', 'ć']
>>>
>>> re.findall(r'\w', text, flags=re.ASCII)
['c', 'z', 'e']

6.6.6. Case Study 1

import re

text = """
# TODO: poprawić cośtam
# todo: sadads

stodoła
metodologia
ortodonta
autodoc
autodoping
"""


re.findall(r'todo', text)
# ['todo', 'todo', 'todo', 'todo', 'todo', 'todo']

re.findall(r'\Btodo\B', text)
# ['todo', 'todo', 'todo', 'todo', 'todo']

re.findall(r'\btodo\b', text)
# ['todo']

re.findall(r'\btodo\b', text, flags=re.IGNORECASE)
# ['TODO', 'todo']

6.6.7. Case Study 2

import re

CODE = """

imie = "Mark"
print(imie)

"""

variable = re.findall(r'^([a-z]+) =', CODE, flags=re.MULTILINE)
print(variable)

import re

CODE = """

Imie = "Mark"
print(Imie)

"""

variable = re.findall(r'^([a-zA-Z]+) =', CODE, flags=re.MULTILINE)
print(variable)

import re

CODE = """

Imie1 = "Mark"
print(Imie1)

"""

variable = re.findall(r'^([a-zA-Z0-9]+) =', CODE, flags=re.MULTILINE)
print(variable)

import re

CODE = """

Imie_1 = "Mark"
print(Imie_1)

"""

variable = re.findall(r'^([a-zA-Z0-9_]+) =', CODE, flags=re.MULTILINE)
print(variable)

import re

CODE = """

Imię_1 = "Mark"
print(Imię_1)

"""

variable = re.findall(r'^([a-zA-Z0-9_ąężżćńłśóĄĘŻŻĆŃŁŚÓ]+) =', CODE, flags=re.MULTILINE)
print(variable)

import re

CODE = """

Imię_1 = "Mark"
print(Imię_1)

"""

variable = re.findall(r'^(\w+) =', CODE, flags=re.MULTILINE)
print(variable)

6.6.8. Use Case - 1

  • Phone

>>> phone = '+48 123 456 789'
>>> re.findall(r'\d', phone)
['4', '8', '1', '2', '3', '4', '5', '6', '7', '8', '9']
>>> phone = '+48 (12) 345 6789'
>>> re.findall(r'\d', phone)
['4', '8', '1', '2', '3', '4', '5', '6', '7', '8', '9']

6.6.9. Use Case - 2

  • Compare Phones

>>> PHONE1 = '+48 123 456 789'
>>> PHONE2 = '+48 (12) 345 6789'
>>>
>>> phone1 = re.findall(r'\d', PHONE1)
>>> phone2 = re.findall(r'\d', PHONE2)
>>>
>>> phone1 == phone2
True

6.6.10. Use Case - 3

  • EU VAT Tax ID

>>> number = '777-286-18-23'
>>> re.findall(r'\d', number)
['7', '7', '7', '2', '8', '6', '1', '8', '2', '3']
>>> number = '777-28-61-823'
>>> re.findall(r'\d', number)
['7', '7', '7', '2', '8', '6', '1', '8', '2', '3']
>>> number = '7772861823'
>>> re.findall(r'\d', number)
['7', '7', '7', '2', '8', '6', '1', '8', '2', '3']

6.6.11. Use Case - 4

  • Number and Spaces

>>> TEXT = 'Email from Mark Watney <mwatney@nasa.gov> received on: Sun, Jan 2nd, 2000 at 12:00 AM'
>>> re.findall(r'[0-9]\s', TEXT)
['0 ', '0 ']
>>> re.findall(r'\d\s', TEXT)
['0 ', '0 ']

6.6.12. 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 CharacterClass
# - Difficulty: easy
# - Lines: 2
# - Minutes: 2

# %% English
# 1. Define `result: str` with regular expression to find:
#    - all digits
#    - all non-digits
# 2. Run doctests - all must succeed

# %% Polish
# 1. Zdefiniuj `result: str` z wyrażeniem regularnym aby wyszukać:
#    - wszystkie cyfry
#    - wszystkie nie-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)
['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)
>>> result = sorted(set(result))
>>> pprint(result, compact=True, width=72)
['\\n', ' ', "'", '(', ')', ',', '.', ':', 'A', 'B', 'C', 'D', 'E', 'J',
 'L', 'M', 'N', 'P', 'R', 'T', 'U', 'V', 'a', 'b', 'c', 'd', 'e', 'f',
 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't',
 'u', 'w', 'x', 'y', 'z']
"""

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(...)
# type: str
result_a = r''

# Find all non-digits in text
# Example: '\\n', ' ', "'", '(', ')', ',', ...
# Note: define only regex pattern (str), not re.findall(...)
# type: str
result_b = 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 CharacterClass
# - Difficulty: easy
# - Lines: 2
# - Minutes: 2

# %% English
# 1. Define `result: str` with regular expression to find:
#    - whitespace characters
#    - non-whitespace characters
# 2. Run doctests - all must succeed

# %% Polish
# 1. Zdefiniuj `result: str` z wyrażeniem regularnym aby wyszukać:
#    - białe-znaki
#    - nie-białe-znaki
# 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)
[' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '\\n', ' ', ' ', ' ', ' ', ' ',
 ' ', ' ', ' ', ' ', ' ', '\\n', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
 ' ', ' ', ' ', '\\n', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
 ' ', '\\n', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
 '\\n', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '\\n',
 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '\\n', ' ', ' ',
 ' ', ' ', ' ', ' ', ' ', ' ', ' ', '\\n', ' ', ' ', ' ', ' ', ' ', ' ',
 ' ', ' ', ' ', ' ', ' ', ' ', ' ', '\\n', ' ', ' ', ' ', ' ', ' ', ' ',
 ' ', ' ', ' ', ' ', ' ', ' ', ' ', '\\n', ' ', ' ', ' ', ' ', ' ', ' ',
 ' ', ' ', ' ', ' ', ' ', '\\n']

>>> 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 whitespace characters in text
# Example: '\n', ' '
# Note: define only regex pattern (str), not re.findall(...)
# type: str
result_a = r''

# Find all non-whitespace characters in text
# Example: "'", '(', ')', ',', '.', '0', '1', '2', '3', '4', '5', '6', ...
# Note: define only regex pattern (str), not re.findall(...)
# type: str
result_b = 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 CharacterClass
# - Difficulty: easy
# - Lines: 3
# - Minutes: 2

# %% English
# 1. Define `result: str` with regular expression to find:
#    - word characters
#    - non-word characters
# 2. Run doctests - all must succeed

# %% Polish
# 1. Zdefiniuj `result: str` z wyrażeniem regularnym aby wyszukać:
#    - znaki słów
#    - nie-znaki słów
# 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', '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']

>>> result = re.findall(result_b, DATA)
>>> pprint(result, compact=True, width=72)
[' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '\\n', ' ', ' ', ' ', '.', ' ',
 ' ', '(', ')', ' ', ' ', ' ', ' ', ' ', '\\n', ' ', '(', ')', ' ', ' ',
 ' ', ' ', ' ', ' ', ' ', ' ', '(', ')', ' ', ' ', '\\n', ' ', ',', ' ',
 ' ', ' ', ':', ' ', ',', ' ', ' ', ' ', ' ', ' ', ' ', '\\n', ' ', ' ',
 '(', ')', ' ', ' ', ' ', "'", ' ', ' ', '(', ')', ' ', ' ', ' ', ' ',
 ' ', ',', '\\n', ' ', ' ', ',', ' ', ' ', ' ', ':', ':', ' ', '.', ' ',
 ' ', ' ', ' ', ' ', ' ', '.', '\\n', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
 ' ', ' ', ' ', ' ', '\\n', ' ', ' ', ' ', '.', ' ', ' ', ' ', ' ', ' ',
 '.', ' ', '\\n', '(', '.', ' ', ')', ' ', ' ', ' ', ' ', ' ', ' ', ' ',
 ' ', ' ', ' ', ' ', ' ', '\\n', '(', ')', ' ', ' ', ' ', ' ', ' ', '(',
 ')', ' ', ' ', ' ', ' ', ',', ' ', ' ', ' ', ' ', '\\n', "'", ' ', ' ',
 ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', ' ', '\\n', '.']
"""

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 word characters in text, don't use range [...]
# Example: 'A', 'A', 'M', 'C', 'C', 'D', 'R', ...
# Note: define only regex pattern (str), not re.findall(...)
# type: str
result_a = r''

# Find all non-word characters in text
# Example: '\n', ' ', "'", '(', ')', ',', '.', ':'
# Note: define only regex pattern (str), not re.findall(...)
# type: str
result_b = 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 CharacterClass
# - Difficulty: easy
# - Lines: 1
# - Minutes: 2

# %% English
# 1. Define `result: str` with regular expression to find:
#    - two uppercase letter acronyms (e.g. 'LM', 'CM')
# 2. Run doctests - all must succeed

# %% Polish
# 1. Zdefiniuj `result: str` z wyrażeniem regularnym aby wyszukać:
#    - dwu wielko-literowe akronimy (np. 'LM', 'CM')
# 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, DATA)
>>> pprint(result, compact=True, width=72)
['LM', 'CM']
"""

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 two uppercase letter acronyms
# Example: 'LM', 'CM'
# Note: define only regex pattern (str), not re.findall(...)
# 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 CharacterClass
# - Difficulty: easy
# - Lines: 2
# - Minutes: 2

# %% English
# 1. Define `result: str` with regular expression to find:
#    - all two-letter conjunctives (two-letter words)
#    - all two-letter pairs embedded in the words
# 2. Run doctests - all must succeed

# %% Polish
# 1. Zdefiniuj `result: str` z wyrażeniem regularnym aby wyszukać:
#    - wszystkie dwu literowe spójniki (dwu-literowe słowa)
#    - wszystkie dwu literowe pary wbudowane w słowach
# 2. Uruchom doctesty - wszystkie muszą się powieść

# %% Hints
# - Use r-string

# %% 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)
['on', 'on', 'at', 'to', 'on', 'at', 'kg', 'of', 'to', 'to', 'as', 'in',
 'on', 'to']

>>> result = re.findall(result_b, DATA)
>>> pprint(result, compact=True, width=72)
['po', 'll', 'me', 'ri', 'ca', 'pa', 'ce', 'fl', 'ig', 'ha', 'ir', 'an',
 'de', 'um', 'an', 'oo', 'om', 'ma', 'nd', 'ei', 'rm', 'st', 'ro', 'un',
 'od', 'ul', 'il', 'uz', 'ld', 'ri', 'an', 'de', 'po', 'll', 'un', 'od',
 'ul', 'ag', 'ul', 'rm', 'st', 'ro', 'ec', 'am', 'ir', 'er', 'so', 'te',
 'nt', 'oo', 'ur', 'fa', 'ou', 'in', 'ut', 'at', 'ul', 'ld', 'ri', 'oi',
 'ne', 'in', 'ut', 'at', 'he', 'pe', 'ou', 'in', 'ut', 'xp', 'lo', 'ri',
 'it', 'he', 'am', 'ra', 'nq', 'ui', 'li', 'as', 'po', 'an', 'di', 'rm',
 'st', 'ro', 'ld', 'ri', 'ol', 'le', 'ct', 'ou', 'nd', 'un', 'at', 'er',
 'ia', 'ri', 'ac', 'ar', 'il', 'ic', 'ha', 'ol', 'li', 'le', 'om', 'ma',
 'od', 'ul', 'ol', 'um', 'bi', 'un', 'rb', 'er', 'oo', 'ur', 'fa', 'ou',
 'in', 'ut', 'ef', 'or', 'if', 'ti', 'ej', 'oi', 'ol', 'um', 'bi']
"""

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 two-letter conjunctives in text (standalone two-letter words)
# Example: 'on', 'on', 'at', 'to', ...
# Note: define only regex pattern (str), not re.findall(...)
# type: str
result_a = r''

# Find all two-letter pairs embedded in the words
# Example: 'po', 'll', 'me', 'ri', 'ca', 'pa', 'ce', ...
# Note: define only regex pattern (str), not re.findall(...)
# type: str
result_b = 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 CharacterClass
# - Difficulty: easy
# - Lines: 2
# - Minutes: 2

# %% English
# 1. Define `result: str` with regular expression to find:
#    - all first three lowercase letters from each word
#    - all last three lowercase letters from each word
# 2. Run doctests - all must succeed

# %% Polish
# 1. Zdefiniuj `result: str` z wyrażeniem regularnym aby wyszukać:
#    - wszystkie pierwsze trzy małe litery z każdego słowa
#    - wszystkie ostatnie trzy małe litery z każdego słowa
# 2. Uruchom doctesty - wszystkie muszą się powieść

# %% Hints
# - Use r-string

# %% 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)
['spa', 'tha', 'fir', 'lan', 'hum', 'lun', 'mod', 'pil', 'lan', 'bec',
 'fir', 'per', 'ste', 'ont', 'sur', 'hou', 'min', 'lat', 'joi', 'min',
 'lat', 'spe', 'hou', 'min', 'exp', 'sit', 'the', 'nam', 'upo', 'lan',
 'col', 'pou', 'lun', 'mat', 'bri', 'bac', 'pil', 'fle', 'lun', 'orb',
 'wer', 'sur', 'hou', 'min', 'bef', 'lif', 'rej']

>>> result = re.findall(result_b, DATA)
>>> pprint(result, compact=True, width=72)
['llo', 'can', 'ght', 'hat', 'rst', 'ded', 'ans', 'oon', 'der', 'eil',
 'ong', 'nar', 'ule', 'lot', 'uzz', 'rin', 'ded', 'llo', 'nar', 'ule',
 'gle', 'uly', 'ong', 'ame', 'rst', 'son', 'tep', 'nto', 'oon', 'ace',
 'urs', 'tes', 'ter', 'uly', 'rin', 'ned', 'tes', 'ter', 'hey', 'ent',
 'urs', 'tes', 'ing', 'ite', 'hey', 'med', 'ity', 'ase', 'pon', 'ing',
 'ong', 'rin', 'ted', 'nds', 'nar', 'ial', 'ing', 'ack', 'rth', 'lot',
 'ael', 'ins', 'lew', 'and', 'ule', 'bia', 'nar', 'bit', 'ere', 'oon',
 'ace', 'urs', 'tes', 'ore', 'ing', 'oin', 'bia']
"""

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 first three lowercase letters from each word
# Example: 'spa', 'tha', 'fir', 'lan', 'hum', 'lun', ...
# Note: define only regex pattern (str), not re.findall(...)
# type: str
result_a = r''

# Find all last three lowercase letters from each word
# Example: 'llo', 'can', 'ght', 'hat', 'rst', 'ded', ...
# Note: define only regex pattern (str), not re.findall(...)
# type: str
result_b = r''