RegEx匹配来自close open标签的文本换行

时间:2013-10-01 08:12:43

标签: php regex

跟随字符串必须匹配

das is<C strike ><c1>t ein text </c1></C><C u ><c1>der </c1></C><C b u ><c1>hier </c1></C>im <C i u ><c1>editor </c1></C><u></u>steht

我的正则表达式不起作用

>(.*?)<

那匹配标签之间的所有文字, 但我只需要按照结果,因为我只有感兴趣的文字没有任何TAG的扭曲(对于这样的样本)

match[0] ------> das is
match[1] ------> im 
match[2] ------> steht

但我变成了这个:

match[0] ------> das is
match[1] ------> t ein text 
match[2] ------> der 
match[3] ------> hier 
match[4] ------> im 
match[5] ------> editor 
match[6] ------> steht

1 个答案:

答案 0 :(得分:0)

我在另一个question中建议使用这个正则表达式,我想这完全适合你的情况:

(?:(?![^<>]*(?:>))[^<])+

regex101 demo

顺便使用preg_match_all

编辑:你可以试试这个:

([^<>]+)(<[^>]+>(?:[^<>]*|(?2))</[^>]+>)*

viper-7 demo

或其他正则表达式:

(?:(?![^<>]*(?:>))[^<](?![^<>]*</))+
相关问题