【问题标题】:How to find value based on key Regex如何根据键正则表达式查找值
【发布时间】:2021-12-12 09:07:46
【问题描述】:

我想使用正则表达式根据键提取值,但找不到表达式。

我在互联网和 StackOverflow 上尝试了很多可用的表达式,但没有任何效果。 这是我想做的一个例子-

给定字符串-

{"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}

我想提取“steps”键的值,即 3972(对于这个例子)

【问题讨论】:

    标签: regex cross-browser


    【解决方案1】:

    您可以在此处使用lookbehind:

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

    这是一个demo,表明正则表达式正在运行。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-07-02
      • 1970-01-01
      • 2012-06-09
      相关资源
      最近更新 更多