解決 wildcard 問題

This commit is contained in:
tdc 2025-04-15 12:01:42 +08:00
parent ac3ac2b63a
commit 5f29a595f0

View File

@ -79,9 +79,10 @@ async def to_hosts(filename: str, data: str, newversion: str):
with open(newfilename, "w") as output:
if name == "hosts":
pattern = r"(?<=^\|\|)\S+\.\S{2,}(?=\^)"
newoutput = "\n".join(
"0.0.0.0 " + e for e in re.findall(pattern, newdata, re.MULTILINE)
)
newoutput = ""
for e in re.findall(pattern, newdata, re.MULTILINE):
if "*" not in e:
newoutput += "0.0.0.0 " + e + "\n"
else:
newoutput = "\n".join("0.0.0.0 " + e for e in data)
output.write(newhead)