【发布时间】:2019-11-03 13:16:27
【问题描述】:
我知道在给定的字符串中只选择单词或只选择 HTML 标记是可能的。但是可以同时选择吗?
在这个例子中,假设我们要选择 前 5 个单词和 HTML 标签:
输入:
<p><strong>This is</strong> <span style="font-size: 1em;">test</span> <strong><em>five</em></strong> words.</p>
test <p>Lorem Ipsum is simply dummy text of the printing and typesetting industry.</p>
预期输出:
<p><strong>This is</strong> <span style="font-size: 1em;">test</span> <strong><em>five</em></strong> words.</p>
编写正则表达式来匹配所有单词或匹配所有 HTML 标记很简单,但不知道如何仅使用正则表达式来实现上述结果。
【问题讨论】:
-
我相信您必须使用拆分的东西编写自定义程序逻辑。 stackoverflow.com/questions/30866275/…
标签: javascript regex