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