提问者:小点点

正则表达式,用于包含中间标记的单词


我有一个内容。我把这一段分成了几行,以便能解释清楚。

 <p>The most 
 i<del class="del" editid="6">m</del>por<ins class="ins">sss</ins>t<del class="del>a</del>n<ins class="ins">sss</ins>t 
 reso<del class="del">ur</del>ce 
 for all develo<ins class="ins">vvv</ins>pers 
 working with , 
 integratin<del class="del">g i</del>t
 with their 
 <ins class="ins">ssss</ins>w<ins class="ins">ss</ins><del class="del">e</del><ins class="ins">ss</ins>bsi<del class="del">te</del>s 
 and applications, 
 an<ins class="ins">sss</ins>d<del class="del"> </del>customizing
 to their needs. You can start from here. 

在这里,我有包含

我试图写一个正则表达式,它识别由这些组成的单词

请注意,regex只突出显示带有

在这里,单词的意思是它必须在一个空格之后开始,直到找到一个空格(空格不在

例如,在内容中,单词是

  i<del class="del" editid="6">m</del>por<ins class="ins">sss</ins>t<del class="del>a</del>n<ins class="ins">sss</ins>t 

  reso<del class="del">ur</del>ce

  integratin<del class="del">g i</del>t

  <ins class="ins">ssss</ins>w<ins class="ins">ss</ins><del class="del">e</del><ins class="ins">ss</ins>bsi<del class="del">te</del>s

  an<ins class="ins">sss</ins>d<del class="del"> </del>customizing

如何编写正则表达式来识别具有此类条件的单词。请帮忙。


共1个答案

匿名用户

Regex101

text = ['<p>The most '
    ,' i<del class="del" editid="6">m</del>por<ins class="ins">sss</ins>t<del class="del>a</del>n<ins class="ins">sss</ins>t '
    ,' reso<del class="del">ur</del>ce '
    ,' for all develo<ins class="ins">vvv</ins>pers '
    ,' working with , '
    ,' integratin<del class="del">g i</del>t'
    ,' with their '
    ,' <ins class="ins">ssss</ins>w<ins class="ins">ss</ins><del class="del">e</del><ins class="ins">ss</ins>bsi<del class="del">te</del>s '
    ,' and applications, '
    ,' an<ins class="ins">sss</ins>d<del class="del"> </del>customizing'
    ,' to their needs. You can start from here.'
].join('\n');
text.match(/(\s|^)(\S{0,}<(del|ins).*>(.*)<\/(del|ins)>\S{0,})(\s|$)/g);

结果:

Array 
0 " i<del class="del" editid="6">m</del>por<ins class="ins">sss</ins>t<del class="del>a</del>n<ins class="ins">sss</ins>t "
1 " reso<del class="del">ur</del>ce "
2 " develo<ins class="ins">vvv</ins>pers "
3 " integratin<del class="del">g i</del>t "
4 " <ins class="ins">ssss</ins>w<ins class="ins">ss</ins><del class="del">e</del><ins class="ins">ss</ins>bsi<del class="del">te</del>s "
5 " an<ins class="ins">sss</ins>d<del class="del"> </del>customizing "
length 6