【发布时间】:2019-06-20 16:31:52
【问题描述】:
我有如下字符串
<p><strong>I am a strongPerson</strong></p>
我想像这样隐藏这个字符串
<p><strong>I am a weakPerson</strong></p>
当我尝试下面的代码时
let old = "<p><strong>I am a strongPerson</strong></p>"
let new = old.replacingOccurrences(of: "strong", with: "weak")
print("\(new)")
我得到像
这样的输出<p><weak>I am a weakPerson</weak></p>
但我需要这样的输出
<p><strong>I am a weakPerson</strong></p>
我的条件是
1.只有当单词不包含“”这样的HTML标签时才需要替换。
帮我拿到它。提前致谢。
【问题讨论】:
-
这很容易用正则表达式
-
@Sh_Khan 你能帮我写正则表达式吗?
标签: swift swift-string