Forum Discussion
nmrao
Champion Level 3
Can you please check the below regex?
(ProcessingMilliseconds"[\s?]*:[\s?]*[\d]+[\.][\d]*,)
By the way, special characters needs to be escaped in the above string.
def regEx = "(ProcessingMilliseconds\"[\\s?]*:[\\s?]*[\\d]+[\\.][\\d]*,)"
The above can handle if there is space before and after ":" and no alphabets after decimal till "," is the next character.
Here is simple positive case:
def str = '''{"ProcessingMilliseconds": 11.34,"ResponseCount":1,"ProcessingMachine":"QAC1","ApplicationVersion":"2.1.766.10728","BuildNumber":"2.1.766.10728","EnvironmentName":"QA","MethodName":"/MemberStore/123/2.1/Routers/QualifiedQuotas"}''' def regEx = "(ProcessingMilliseconds\"[\\s?]*:[\\s?]*[\\d]+[\\.][\\d]*,)" def result = (str =~ regEx) //Equal to 1, because there must be one match. assert result.count ==1
Test for failure:
kbourdel
8 years agoOccasional Contributor
Thanks for your reply.
The trick was escaping the special characters in the regex portion & reworking the code a bit
def Detail = messageExchange.responseHeaders["WEBAPI_RESPONSE_DETAIL"] log.info("Detail: "+ Detail) def regEx = ".*ProcessingMilliseconds\":([0-9\\.]*).*" slaheader = ( Detail[0] =~ regEx ) log.info ('slaheader ' + slaheader[0][1])
Related Content
- 5 years agoNinjaMarvel
- 7 years agoDonkey2017
- 6 years agomartonjurak