开发者

Negating a word within a line using regular expression

Given the this expression that matches lines that contain minOccurs

<xs:element[^>]+?\sminOccurs\s*=[^>]+>

and this text:

<xs:element name="shipto">
  <xs:complexType>
    <xs:sequence>
      <xs:element name="name" type="xs:string"/>
      <xs:element name="address" type="xs:string"/>
      <xs:element name="city" minOccurs="1" type="xs:string"/>
      <xs:element name="country" minOccurs="1" type="xs:string"/&g开发者_Go百科t;
    </xs:sequence>
  </xs:complexType>
</xs:element>

how do I change it from matching xs:element lines that contain minOccurs to xs:element lines that don't contain minOccurs.

The output expected would be this:

<xs:element name="name" type="xs:string"/>
<xs:element name="address" type="xs:string"/>


Use XML engine instead of regex. Appropriate XPath:

//xs:element[not(@minOccurs)]

Regex:

<xs:element(?![^>]+?minOccurs=".*?")[^>]*>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜