0
votes

$string = "Response 22: 404 (8345ms), headers: Accept-Ranges=bytes, Cache-Control=no-cache, no-store, private, Connection=close, Content-Encoding=gzip, Content-Language=it-it, Content-Length=1674, Content-Location=index.html.it-it, Content-Type=text/html; charset=utf-8, Date=Wed, 24 Sep 2014 19:01:30 GMT, ETag='eb1-50331586750c0;503ac178f62dd', Last-Modified=Tue, 16 Sep 2014 16:35:55 GMT, Server=Apache, Strict-Transport-Security=max-age=31536000; includeSubDomains, TCN=choice, Vary=negotiate,accept,accept-language,Accept-Encoding, X-Frame-Options=SAMEORIGIN, X-UA-Compatible=IE=Edge";

Here I want to grab response number(=> 22), response code(=> 404) and its milli seconds(=> 8345ms). I think I have to use regex, but I am new to that. Can you please give any suggestions?

1
you can always use getallHeaders() to grab and array of headers and then conveniently iterateSatya
If the format is always the same, just juse a couple of explode(). Much easier then trying to write a complicated regex, in my opinion.Michel
Why you people see regex as a complicated one?Avinash Raj
Thanks Avinash. I didn't mean its complicated ;), but I am very new to regex. Hope I can learn soon. Could you please suggest me some good online tutorials for the same.Ramesh Raja
this would help you regular-expressions.infoAvinash Raj

1 Answers

0
votes
Response\s*(\d+):\s*(\d+)\s*\((\S+)?\)

Try this.Get the three groups.See demo.

http://regex101.com/r/qC9cH4/3