-1
HTTP/1.1 200 
X-Application-Context: fss-proxy
Date: Tue, 03 Apr 2018 11:38:13 GMT
X-Content-Type-Options: nosniff
X-XSS-Protection: 1; mode=block
Cache-Control: no-cache, no-store, max-age=0, must-revalidate
Pragma: no-cache
Expires: 0
X-Frame-Options: DENY
Access-Control-Allow-Credentials: true
Access-Control-Allow-Methods: GET, POST, OPTIONS, PUT, DELETE, PATCH
Access-Control-Allow-Headers: Authorization,Content-Type,If-Modified-Since,headers,If-Modified-Since
Content-Type: application/json;charset=UTF-8
Transfer-Encoding: chunked
Connection: close

18

activeSessionsCount=1

0

I have JSON here. And I want to grab only integer that may vary from 0 to like 200 or even more using regex in the current string "activeSessionsCount=1". Is it possible? I'm completely stuck here.

Biffen
  • 5,354
  • 5
  • 27
  • 32
  • 3
    Hi! This does not look like json. But json should be parsed, not using regex. Please post your own efforts. Thank you. – Lance Toth Apr 03 '18 at 13:04
  • 2
    This server is producing invalid JSON as Lance mentioned. If you can fix the server-side you should probably do, especially if the application is going to serve more JSON. If you can't, I'd just consider this response's body as plain text, split around `=` and use the right part, after checking that the right part is `activeSessionsCount` if needed. – Aaron Apr 03 '18 at 13:11
  • Hi there again! – Robert Bartosevic Apr 03 '18 at 13:38
  • But if this could be just simple text, is there any possibilities to grab only that integer using regex? I tried regex101.com tester and i failed. BTW im using zabbix which is parsing json data(text above). – Robert Bartosevic Apr 03 '18 at 13:46

1 Answers1

0

It kind of depends on the language you use for regex parsing - functions and methods would be different. In general though it could be as simple as /.*activeSessionsCount=(\d+)/gm

Varrah
  • 80
  • 1
  • 9