From 5c6f51bdaa75f1834e49b50c2fc03172ec8c3a28 Mon Sep 17 00:00:00 2001 From: misyaguziya Date: Sun, 8 Sep 2024 05:48:46 +0900 Subject: [PATCH] =?UTF-8?q?=F0=9F=9A=A7=20[WIP/TEST]=20=E3=83=97=E3=83=AC?= =?UTF-8?q?=E3=83=BC=E3=82=B9=E3=83=9B=E3=83=AB=E3=83=80=E3=83=BC=E3=81=AE?= =?UTF-8?q?=E5=BD=A2=E5=BC=8F=E3=82=92=E4=BF=AE=E6=AD=A3=20ex)=20"=20<$=20?= =?UTF-8?q?0x1000>=20"=20->=20"=20$=200x1000=20"?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit $と0x1000の間にスペースが入る事があるため、それを考慮して正規表現を修正 --- src-python/webui_controller.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src-python/webui_controller.py b/src-python/webui_controller.py index 61db6aec..90fa9526 100644 --- a/src-python/webui_controller.py +++ b/src-python/webui_controller.py @@ -3,8 +3,6 @@ from time import sleep from subprocess import Popen from threading import Thread import re -import random -import string from config import config from model import model from utils import getKeyByValue, isUniqueStrings, printLog, printResponse @@ -297,10 +295,10 @@ def replaceExclamationsWithRandom(text): def replace(match): original = match.group(1) nonlocal num - rand_value = f" <$ {hex(num)}> " + rand_value = hex(num) replacement_dict[rand_value] = original num += 1 - return str(rand_value) + return f" ${rand_value} " # 文章内の ![] の部分を置換 replaced_text = re.sub(pattern, replace, text) @@ -310,8 +308,9 @@ def replaceExclamationsWithRandom(text): def restoreText(escaped_text, escape_dict): # 大文字小文字を無視して置換するために、正規表現を使う for escape_seq, char in escape_dict.items(): - # escape_seq の部分を case-insensitive で置換 - escaped_text = re.sub(re.escape(escape_seq[1:-1]), char, escaped_text, flags=re.IGNORECASE) + # escaped_text の部分を pattern で置換 + pattern = re.escape(f"${escape_seq}") + r"|\$\s+" + re.escape(escape_seq) + escaped_text = re.sub(pattern, char, escaped_text, flags=re.IGNORECASE) return escaped_text def removeExclamations(text):