Home > Net >  How to find value based on key Regex
How to find value based on key Regex

Time:10-27

I want to extract the value based on the key using regex but am not able to find the expression.

I tried lots of expressions available on the internet and StackOverflow but nothing is working. Here is an example of what I want to do-

Given String-

{"summaryId":"x436a218-61703d00-15180-6","calendarDate":"2021-10-21","activityType":"WALKING","activeKilocalories":119,"bmrKilocalories":2283,"steps":3972,"distanceInMeters":2919.0,"durationInSeconds":86400,"activeTimeInSeconds":2786,"startTimeInSeconds":1634745600,"startTimeOffsetInSeconds":28800,"moderateIntensityDurationInSeconds":0,"vigorousIntensityDurationInSeconds":0,"stepsGoal":7500,"intensityDurationGoalInSeconds":9000,"floorsClimbedGoal":10}

I want to extract the value of the "steps" key i.e 3972 (for this example)

CodePudding user response:

You could use a lookbehind here:

(?<="steps":)[^,] 

Here is a demo showing that the regex is working.

  • Related