[英]Javascript Regex matching xml tags
I am going to match something like <textEntryInteraction responseIdentifier="RESPONSE" expectedLength="15"/>
, and I want it to be occur once only. 我将匹配类似<textEntryInteraction responseIdentifier="RESPONSE" expectedLength="15"/>
,并且我希望它只出现一次。 When I use /<textEntryInteraction [^>]+\\/>/g
to search and match the tags, I don't know why pattern.test(xml)
return false. 当我使用/<textEntryInteraction [^>]+\\/>/g
搜索和匹配标签时,我不知道为什么pattern.test(xml)
返回false。
However, if i use /<textEntryInteraction [^>]+\\/>/
, it return true. 但是,如果我使用/<textEntryInteraction [^>]+\\/>/
,则返回true。
Can anyone helps me? 谁能帮我?
If I were you I would seriously consider looking at jQuery instead of regex for this type of work. 如果我是您,我会认真考虑使用jQuery而不是正则表达式来进行此类工作。 You can do something like this. 你可以做这样的事情。
var $xml = $($.parseXML(yourXMLcontent));
var $textEntries = $xml.find('textEntryInteraction');
You can then filter your textEntries by attribute values . 然后,您可以按属性值过滤textEntries 。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.