【发布时间】:2025-12-18 20:35:01
【问题描述】:
我目前有这样的正文
text = "hello this [is a cool] line of text that might have [two] brackets.
我需要的是解析和替换这个文本,所以在这个例子中它最终会像
text = "hello this <a href='/phrase/is a cool/'>is a cool</a> line of text that might have <a href='/phrase/two/'>two</a> brackets.
现在我认为在正则表达式中找到所有括号都是\[.*?\],但我不确定如何具体执行此操作。
【问题讨论】:
-
你能用
{}代替[]吗? -
@Jortega 我想
-
好了,现在我们可以使用
.format,省力了。 -
这有帮助吗? *.com/questions/11096720/…
标签: python