话不多说,开始今天的内容
import re
import webbrowser
from easygui import *
from tkinter.messagebox import *
import tkinter
import pyperclip
root = tkinter.Tk()
root.withdraw()
match_ans = ''
match_ans2 = ''
match_ques = ['', '', '', '', '']
lmatch_ans = 0
replace_ans = ''
replace_ques = ['', '', '', '']
while True:
ans = buttonbox('请选择功能', '选择', ['教程', '使用必看', '匹配表达式+替换', '替换文本'])
if ans == '教程':
webbrowser.open('https://www.runoob.com/regexp/regexp-tutorial.html')
elif ans == '使用必看':
msgbox('每次的显示的结果会复制到剪贴板上\n第一行为搜索结果\n第二行为替换结果')
elif ans == '匹配表达式+替换':
while True:
match_ques = multenterbox('请输入', '匹配表达式+替换', ['请输入表达式', '请输入文本', '请输入要替换的内容', '搜索结果', '替换结果'], [match_ques[0], match_ques[1], match_ques[2], f'共匹配{lmatch_ans}项{match_ans}', match_ans2])
if match_ques == None:
match_ans = ''
match_ans2 = ''
match_ques = ['', '', '']
lmatch_ans = 0
break
else:
try:
match_ans = re.findall(match_ques[0], match_ques[1])
if match_ans == ['']:
lmatch_ans = 0
else:
lmatch_ans = len(match_ans)
match_ans2 = re.sub(match_ques[0], match_ques[2], match_ques[1])
pyperclip.copy(f'共匹配{lmatch_ans}项{match_ans}\n{match_ans2}')
except:
showerror('错误', '正则表达式输入错误')
elif ans == '替换文本':
while True:
replace_ques = multenterbox('请输入', '替换文本', ['请输入文本', '请输入要替换的文本', '请输入替换内容', '结果'], [replace_ques[0], replace_ques[1], replace_ques[2], replace_ans])
if replace_ques == None:
replace_ans = ''
replace_ques = ['', '', '', '']
break
else:
try:
replace_ans = str(replace_ques[0]).replace(replace_ques[1], replace_ques[2])
pyperclip.copy(replace_ans)
except:
showerror('错误', '无法替换')
else:
break
如果喜欢作者可以打赏一下