正则表达式,用于检测句子中缺少的XML Open标记 [英] Regular expression to detect missing XML Open tag in a sentence

查看:84
本文介绍了正则表达式,用于检测句子中缺少的XML Open标记的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我输入以下句子:

今天天气< weather> Sunny < / weather> ,温度为29摄氏度< /温度>

Today weather is <weather>Sunny</weather> with temperature of 29 Celcius</temperature>

我需要一个正则表达式来检测句子中缺少的XML开放标记。因此,对于上述句子,它将返回
< / temperature> 没有开放标记。

I need a regular expression to detect missing XML open tag in the sentence. So for above sentence, it will return </temperature> does not have open tag.

在某位专家的帮助下,我使用了  " ;< \w +>(?!。*?< / \ 1>)" 
检测缺少的XML关闭标记。我尝试将模式修改为
(?!< \1>。*?)< /(\ w + + )>
,但无法匹配缺少的XML开放标记。

With the help of some expert, I used "<\w+>(?!.*?</\1>)" to detect missing XML close tag. And I tried to modify the pattern to (?!<\1>.*?)</(\w+)>, but cannot match the missing XML open tag.

有什么想法吗?

谢谢!

推荐答案

对于这种简单的情况,请尝试:

  
< /(\ w +)>(?<!< \1>。*)

   </(\w+)>(?<!<\1>.*)


这篇关于正则表达式,用于检测句子中缺少的XML Open标记的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆