From a1ae100a0a5540bd306a38a2bf194a18bc8c73aa Mon Sep 17 00:00:00 2001 From: Urban Wallasch Date: Sat, 12 Jun 2021 23:52:15 +0200 Subject: [PATCH] * Fixed the unsolicited surrounding whitespace issue in dict line splitter regex by alternating between greedy (whitespace) and non-greedy (payload) quantifiers. --- jiten-pai.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/jiten-pai.py b/jiten-pai.py index b8e35ef..4b25028 100755 --- a/jiten-pai.py +++ b/jiten-pai.py @@ -44,14 +44,13 @@ def dict_lookup(dict_fname, term): with open(dict_fname) as dict_file: # edict example line: # 〆日 [しめび] /(n) time limit/closing day/settlement day (payment)/deadline/ - re_split = re.compile(r'^(.*) *\[(.*)\] */(.*)/$') + re_split = re.compile(r'^\s*(.*?)\s*\[\s*(.*?)\s*\]\s*/\s*(.*?)\s*/\s*$') re_term = re.compile(term) for line in dict_file: try: kanji, kana, trans = re_split.match(line.strip()).groups() except: continue - kanji = kanji.strip() # for now promiscuously try to match anything anywhere if re_term.search(kanji) is not None or \ re_term.search(kana) is not None or \ -- 2.30.2