level 12
选正则表达式函数模式,右边进入创建窗口,全部复制进去,注意缩进。
import re
def replace_duplicate_names(text, names):
if not names:
return text
pattern = names[0]
seen = set()
def repl(match):
name = match.group()
if name in seen:
return names[1]
else:
seen.add(name)
return name
return re.sub(pattern, repl, text)
def replace(match, number, file_name, metadata, dictionaries, data, functions, *args, **kwargs):
text = match.group()
names = ["小明","他"]
return replace_duplicate_names(text, names)
2026年08月31日 04点08分
3
level 7
如果不想写Python的话你可以试试先将所有这个名字换成她,然后再用正则匹配每个<p>里的第一个她,将她替换成名字。
顺便麻烦把重复的标签删一下,禁止套娃。
2026年08月31日 06点08分
4
不会写正则
![[笑尿]](/static/emoticons/u7b11u5c3f.png)
都是找ai弄
2026年08月31日 07点08分