【发布时间】:2021-10-12 13:57:48
【问题描述】:
我在内容中有自定义标签,并且有关键字标签,上面有对应的id号
const tags = ["<i>", "<c>", "<b1>", "<b2>", "<b3>"];
keyword tags e.g. "<key2>", "<key10>"
我必须删除前导和尾随空格,因为我需要按单词拆分。
这是我的示例内容:
let content =
`<b1> <c> "The Modern Amphibians" </c> </b1>
Modern <b>amphibians </b> have a simplified <key2>anatomy </key2> compared to their ancestors due to <i> paedomorphosis</i>.
Caused by two evolutionary trends: <b2> miniaturization </b2> and an unusually.
Don’t think that this term’s work will be <key23> a piece of cake </key23>`
预期的输出将是(删除前导和尾随空格)
let output =
`<b1><c>"The Modern Amphibians"</c></b1>
Modern <b>amphibians</b> have a simplified <key2>anatomy</key2> compared to their ancestors due to <i>paedomorphosis</i>.
Caused by two evolutionary trends: <b2>miniaturization</b2> and an unusually.
Don’t think that this term’s work will be <key23>a piece of cake</key23>`
我尝试制作自己的正则表达式,从 c 标签开始,但我不确定这是否正确,因为我只需要删除空格,但我的正则表达式包含标签。
const customRegex = \((<c>\s)|(\s<\/c>))\g.
有人可以帮忙。谢谢。
【问题讨论】:
标签: javascript regex