Is there a way to check if all key occurrences have the same value?
I am looking for all state running values, but if a container returns a different value (for example "stopped" then return false to the entire regex
{"container-1":{"type":"info","state":"running","started_at":"2022-03-02T21:19:44.042239675Z"},"container-2":{"type":"info","state":"running","started_at":"2022-03-02T21:19:45.451556078Z"},"container-3":{"type":"info","state":"running","started_at":"2022-03-02T21:19:45.21944115Z"}
I alredy filtered the state: running with this regex but how to do the validation to ensure that all the keys match the value "running"
"([^"] ?)"state"\s*:"running"
CodePudding user response:
I don't think there's a way to use a regular expression to test if all the state values are the same.
But if there's a specific value you want to test, use a negative lookahead to reject anything else.
"state"\s*:(?!\s*"running")