Forum Discussion

GlorianChris's avatar
GlorianChris
Occasional Contributor
7 years ago

Using Negative Lookahead in RegEx Assertions

I'm trying to use RegEx in a NotContains response assertion (SOAPUI 5.4.0) to find empty tags that don't have a particular name.

 

For instance, given the response:

<SOAP-ENV:Header xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"/>
   <soap:Body>     
         <ns2:invocationSummary>
            <ns2:version>X.1.0.214</ns2:version>
            <ns2:invocationId>2381305080000000000</ns2:invocationId>
            <ns2:executionTime>235</ns2:executionTime>
            <ns2:timestamp>2018-01-18T15:44:00.891+13:00</ns2:timestamp>
            <ns2:username>demo</ns2:username>
         </ns2:invocationSummary>
         <ns22:accountDetails>
            <ns22:account>
               <ns5:id/>
               <ns5:name>XXXX General</ns5:name>
               <ns6:accountNumber>
                  <ns6:accountNo>XXXX</ns6:accountNo>
                  <ns6:productName>General</ns6:productName>

I need to ignore the line

<SOAP-ENV:Header xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"/>

but match the line

<ns5:id/>

I'm using this in a NotContains Assertion (with RegEx enabled):

(?!(<SOAP-ENV))<.*\/>

This works on the various RegEx testing sites.

 

Any idea why it's working differently in SOAPUI?

Thanks

  • I don't claim to know how Not Contains assertions work (like you, I am a bit puzzled by its behaviour).

     

    But I put your RegEx into a Script assertion and it seems to do what you want:

     

    assert !(messageExchange.response.responseContent =~ /(?!(<SOAP-ENV))<.*\/>/)

     

     

  • JHunt's avatar
    JHunt
    Community Hero

    I don't claim to know how Not Contains assertions work (like you, I am a bit puzzled by its behaviour).

     

    But I put your RegEx into a Script assertion and it seems to do what you want:

     

    assert !(messageExchange.response.responseContent =~ /(?!(<SOAP-ENV))<.*\/>/)