* Fixed the unsolicited surrounding whitespace issue in dict line splitter regex...
authorUrban Wallasch <urban.wallasch@freenet.de>
Sat, 12 Jun 2021 21:52:15 +0000 (23:52 +0200)
committerUrban Wallasch <urban.wallasch@freenet.de>
Sat, 12 Jun 2021 21:52:15 +0000 (23:52 +0200)
jiten-pai.py

index b8e35ef34d9714ecf56970ea4965ac19e0e54687..4b250280e2917dea4d11e8b75361d9b94beecb3f 100755 (executable)
@@ -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 \