无法弄清楚正确的表达方式

时间:2018-02-22 19:49:38

标签: java regex

我有以下字符串:

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:hsn="hsn.us.banner.hsntech.com:message1" xmlns:hsn1="hsn.us.banner.hsntech.com:header" xmlns:hsn2="hsn.us.banner.hsntech.com:payload"><soapenv:Header/><soapenv:Body>
          <msg:L1MessageRequest xmlns:msg="hsn.us.banner.hsntech.com:message1" xmlns:hdr="hsn.us.banner.hsntech.com:header" xmlns:hsn="hsn.us.banner.hsntech.com:payload" xmlns:hsn3="hsn.us.banner.hsntech.com:message1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="hsn.us.banner.hsntech.com:message1 ../HSNLevel1Message.xsd">
             <msg:Header xmlns:msg="hsn.us.banner.hsntech.com:message1">
                <hdr:MsgID>97w000www7</hdr:MsgID>
                <hdr:MsgType>request</hdr:MsgType>
                <hdr:MsgTimestamp>2016-01-05T09:00:00</hdr:MsgTimestamp>
                <hdr:MsgPriority>low</hdr:MsgPriority>
                <hdr:MsgSourceSystem>SUS-SCM</hdr:MsgSourceSystem>
                <hdr:MsgTargetSystem>HSN-Banner</hdr:MsgTargetSystem>
                <hdr:MsgEncryption>false</hdr:MsgEncryption>
                <hdr:MsgVersion>1.0</hdr:MsgVersion>
                <hdr:MsgOperationType>synchronous</hdr:MsgOperationType>
                <hdr:MsgOperationName>
                   <hdr:Verb>UPDATE</hdr:Verb>
                   <hdr:Noun>Account</hdr:Noun>
                </hdr:MsgOperationName>
                <hdr:MsgOperationUser>hcmuser</hdr:MsgOperationUser>
             </msg:Header>
             <msg:Payload xmlns:msg="hsn.us.banner.hsntech.com:message1">
                <msg:UpdateAccountRequest>
                   <hsn:Account>
                    <hsn:AccountID>1415-1415</hsn:AccountID>
                    <hsn:CustomFields>
                        <hsn:CustomField key="HCMAccount" name="HCMAccount" type="hsn:YesNoFlagType">N</hsn:CustomField>
                    </hsn:CustomFields>
                   </hsn:Account>
                </msg:UpdateAccountRequest>

我需要获取<msg:header ..>元素的位置。当我使用以下正则表达式“<[a-z0-9]*:Header.*>”时,由于<soapenv:Header/>,它返回两个值。匹配“<msg:header..>”并排除“<soapenv:Header/>”的正确模式是什么?

感谢

1 个答案:

答案 0 :(得分:0)

使用否定look-behind来断言没有单词soapenv

  

<([a-z0-9]*)(?<!soapenv):Header.*>

相关问题