From a6e6b6353dd9a599780fffceed12b6c1ba4c9128 Mon Sep 17 00:00:00 2001 From: A_D Date: Fri, 10 Jul 2020 05:49:21 +0200 Subject: [PATCH] Tidied regexp Python regexps should always be held in r'' or raw strings, ensuring that python doesn't try to expand the regexp escapes. I also removed the escaped -, as they're only special characters in character groups --- edshipyard.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/edshipyard.py b/edshipyard.py index dd159529..bb5e4ef2 100644 --- a/edshipyard.py +++ b/edshipyard.py @@ -200,7 +200,7 @@ def export(data, filename=None): # Look for last ship of this type ship = companion.ship_file_name(data['ship'].get('shipName'), data['ship']['name']) - regexp = re.compile(re.escape(ship) + '\.\d\d\d\d\-\d\d\-\d\dT\d\d\.\d\d\.\d\d\.txt') + regexp = re.compile(re.escape(ship) + r'\.\d{4}-\d\d-\d\dT\d\d\.\d\d\.\d\d\.txt') oldfiles = sorted([x for x in os.listdir(config.get('outdir')) if regexp.match(x)]) if oldfiles: with open(join(config.get('outdir'), oldfiles[-1]), 'rU') as h: