Forum Discussion

NadiaRanalli's avatar
New Contributor
3 years ago

soapui assertion for timestamp format



I am new to this forum and also to soapui tool.

I am trying to write assertions in soapui to validate some elements. I would like to write an assertion to validate that the timestamp returned in response has always the format as example below:



<soapenv:Envelope xmlns:soapenv="" xmlns:xsd="" xmlns:xsi="">
<InterConnectResponse xmlns="">
<Message>Authorization failed</Message>



can you please help me in writing this assertion from scratch?

Thanks a lot!

2 Replies

  • richie's avatar
    Community Hero

    Hi NadiaRanalli 


    to pattern match a string in an assertion typically regex is used and for simple to even complex strings regex does the job perfectly


    HOWEVER - pattern matching regex against datetimes is quite difficult as it's more difficult than you think to ensure the pattern you specify covers off all illegal dates in perpetuity.


    The following stackoverflow link -->. gives you some idea how complicated it can be to ensure you cover off all the illegals.



    Via stackoverflow, Okipa came up with the following (gotta give credit where it's due! ;))




    I made a couple of tweaks to match your specific value so changed Okipa's regex to the following:




    Just to be clear - I didn't change much - Okipa did all the hard work and his regex validated the following value:


    2021-10-04 14:38:03


    I just altered it to include validation of the literal 'T' along with the fractional seconds and the UTC timezone indicator







    • richie's avatar
      Community Hero



      in my regex I've hardcoded the timezone offset.  if you need it to reflect changing from UTC/GMT timezone to another timezone (e.g BST for British Summer Time or wherever you are in the world) then you'd need to change the regex so that it supports either plus/minus hours offset and the removal of the Z (zero) indicator.