我正在尝试为一个简单的阅读辅助网站突出显示元音。
我有一些HTML,我想突出显示元音,但也有一些HTML我不想弄乱。基本上只有<mark data-trigger="">other word</mark>
来澄清一下。
我有这个:
Hello, this is a <mark data-trigger="">word</mark> that is in the text. I
want to get all vowels and wrap it in spans, but avoid messing with the other
html.我想要的是:
H<span>e</span>ll<span>o</span>, th<span>i</span>s <span>i</span>s a <mark data-trigger="">word</mark> th<span>a</span>t...我知道这会取代所有元音> replace(/(a|e|i|o|u)/ig, "<span class='vowel'>$1</span>")
只需添加“不要在MARK标记内搞乱任何东西”就足够了。
我能用RegExp实现这一点吗?
我可以使用外部库,jQuery或其他任何库。
发布于 2017-05-14 08:13:12
这应该会捕获html标签中没有包含的所有元音,也不会包含在标签中。
/(a|e|i|o|u)|(?:<.*?>.*<\/.*?>)/g
如果您确实想要捕获html标记中的文本,应该是这样的。
/(a|e|i|o|u)|(?:<.*?>)/g
https://stackoverflow.com/questions/43958974
复制相似问题