From 35f66f5712a4d7ae8a55c9d34e0d4766cbc24cde Mon Sep 17 00:00:00 2001 From: lilly Date: Tue, 18 Jul 2023 19:17:12 +0900 Subject: [PATCH] wildcard pattern matching wildcard pattern matching --- README.md | 2 +- wildcards.py | 23 +++++++++++++++++------ 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 6b456e0..b4de2a0 100644 --- a/README.md +++ b/README.md @@ -69,7 +69,7 @@ print(w.run("a{__b__|{c|}|{__d__|e|}|f|}g____ __my__")) -### txt file (UTF8) +### txt file (supports .txt files in different encodings.) from ``` # 주석 comment diff --git a/wildcards.py b/wildcards.py index 7ee64cc..00ab845 100644 --- a/wildcards.py +++ b/wildcards.py @@ -1,7 +1,10 @@ -import glob, sys +import os +import glob +import sys import random import re -import os +import fnmatch + if __name__ == os.path.splitext(os.path.basename(__file__))[0] or __name__ =='__main__': from ConsoleColor import print, console, ccolor else: @@ -23,6 +26,7 @@ if missing: import chardet + # ============================================================ class wildcards: @@ -114,12 +118,16 @@ class wildcards: # 카드 중에서 가져오기 def card(match): - #print(f"card i : {match.group(2)}") - if match.group(2) in wildcards.cards : - r=random.choice(wildcards.cards[match.group(2)]) + #print(f"card in : {match.group(2)}") + lst=fnmatch.filter(wildcards.cards, match.group(2)) + if len(lst)>0: + #print(f"card lst : {lst}") + cd=random.choice(lst) + #print(f"card get : {cd}") + r=random.choice(wildcards.cards[cd]) else : r= match.group(2) - #print(f"card r : {r}") + #print(f"card out : {r}") return r @@ -207,6 +215,9 @@ class wildcards: #print("wildcards test : "+wildcards.run("{9$$-$$a|b|c}")) #print("wildcards test : "+wildcards.run("{9$$ {and|or} $$a|b|c}")) #print("wildcards test : "+wildcards.run("{{slender,|} {nature,|} {curvy,|} {thin,|} {narrow,|} {slim,|} {mini,|} {little,|}| {|very }{-$$ $$thin|slender|narrow|slim|little|skinny|mini} body, }")) +print("wildcards test : "+wildcards.run("__aest__")) +print("wildcards test : "+wildcards.run("__*test__")) +print("wildcards test : "+wildcards.run("__?est__")) print("wildcards test : "+wildcards.run("__test__")) print("wildcards test : "+wildcards.run("__/test__")) print("wildcards test : "+wildcards.run("__/0/test__"))