From d04bd9f1f5236e75f35d62ee9454b81fbba3b488 Mon Sep 17 00:00:00 2001 From: Stephen Moseley Date: Thu, 14 Dec 2023 09:17:21 +0000 Subject: [PATCH] Adds additional comment describing the new Regex usage. --- improver/metadata/amend.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/improver/metadata/amend.py b/improver/metadata/amend.py index c4d0d35c3a..8487e0fcb4 100644 --- a/improver/metadata/amend.py +++ b/improver/metadata/amend.py @@ -86,6 +86,11 @@ def amend_attributes(cube: Cube, attributes_dict: Dict[str, Any]) -> None: """ for attribute_name, value in attributes_dict.items(): re_now = r"({now:.*})" + # We use the DOTALL flag below to tell regex that . should match new-line + # characters as well as everything else. Therefore, the match below is for + # any string that contains the word now inside curly braces, with a colon + # and any format specifier. This now section is returned as a group in + # position 1 of has_now, which we will use to format the current time. has_now = re.match(rf".*{re_now}.*", value, re.DOTALL) if has_now: now = has_now[1].format(now=datetime.now())