7.20. Regex Comment Group
Catch expression results
(?#...)
- commentComments are ignored by the regex engine
7.20.1. SetUp
import re
TEXT = 'On Sun, Jan 1st, 2000 at 12:00 AM Alice <alice@example.com> wrote'
7.20.3. Use Case - 1
re.findall(r'\d{1,2}(?#hour):\d{2}(?#minute)', TEXT)
['12:00']
7.20.4. Use Case - 2
hour = r'\d{1,2}(?#hour)'
minute = r'\d{2}(?#minute)'
time = f'{hour}:{minute}'
re.findall(time, TEXT)
['12:00']
time
'\\d{1,2}(?#hour):\\d{2}(?#minute)'
7.20.2. Comments