问题描述
我有以下正则表达式:
(</?[a-z][a-z0-9]*[^<>]*>)
我有以下文字:
<DIV><P class='abc'>Hello <B>Mister</B>! How are you >..< doing? </P>
<I>I'm good</I></DIV>
现在我想拆分每个标签的文字:
Now I'd like to split the text per tag:
<DIV>
<P class='abc'>
Hello
<B>
Mister
</B>
! How are you >..< doing?
</P>
<I>
I'm good
</I>
</DIV>
如何使用Javascript正则表达式执行此操作?
是否能够获得它工作,但不得不重新开始因为javascript不支持lookbehinds。
How can I do this with Javascript regex?
Is was able to get it to work but had to start over because javascript doesn't support lookbehinds.
(基本上拆分html标签并保留分隔符)
(basically split on html tags and keep the delimiters)
编辑
我的目标是使用html来存储格式。我想将上面的html提供给一个javascript对象。 javascript对象将格式与文本分开,并为常规文本执行格式化对象和操作B的操作A.
My goal with this is to use html to store formatting. I want to feed the html above to a javascript object. The javascript object separates the formatting from the text and does action A for formatting objects and action B for regular text.
我知道这听起来有点模糊,但我不知道我想透露太多关于这个项目的信息。
I know it sounds a bit vague, but I don't want to reveal too much about the project.
推荐答案
我真的同意奥马尔这个问题,但我会给你反正的正则表达式。 :)
I actually agree with Omar on this issue, but I'll give you the regex anyway. :)
\<[^>]+?>|.+?(?=(?:<[^><]+?>|$))
这篇关于Javascript拆分包括分隔符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!