From 225e256acf0e841657ad2c30080bef83ab837cd5 Mon Sep 17 00:00:00 2001 From: ache Date: Fri, 22 May 2020 02:43:13 +0200 Subject: Regex matching --- dicofr.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/dicofr.py b/dicofr.py index 6ae3d3e..ea5741c 100755 --- a/dicofr.py +++ b/dicofr.py @@ -65,7 +65,16 @@ def matching(word): if word == w: matchingWord.append(w) else: - print("Error: Not implemented yet", file=sys.stderr) + if word[-1] != '/' or len(word) <= 2: + print("Erreur: Le format matching pour les regex est /MOT/", + file=sys.stderr) + return [] + import re + regex = re.compile(word[1:-1]) + + for w in listWord: + if regex.match(w): + matchingWord.append(w) return matchingWord @@ -75,6 +84,7 @@ if __name__ == '__main__': print("Erreur: Rechercher un mot", file=sys.stderr) exit() + # Si on n'arrive pas à trouver le dictionnaire if not exists(dico): if not exists(f'{DIR_PATH}/{dico}'): print('Error: No sqlite dictionnary', file=sys.stderr) -- cgit v1.2.3