11

Take the data set as lines of arrays with values, e.g.:

[ "Dog", "cat", "Bird"]

I would like to get an array with all those values that do not match a regex but am unwilling to use negative capture groups (regex is more complicated than that) - so if my criteria would be that first letter must be capital, the output array should be ["cat"]

1 Answer 1

19

all those values that do not match a regex

Sounds like test(_) | not is what you're looking for. Assuming you meant to write "first letter must NOT be a capital", the following filter could be used:

map(select(test("^[A-Z]")|not))
5
  • But then the output is just true/false rather than the value tested
    – Konrads
    Commented May 9, 2018 at 19:00
  • Surely you jest. Or maybe you misplaced a parenthesis?
    – peak
    Commented May 9, 2018 at 19:06
  • he was refering to a filter, that is then popped into the correct select
    – Hvisage
    Commented Aug 17, 2023 at 9:47
  • @Hvisage - In jq, all “functions” are filters.
    – peak
    Commented Aug 17, 2023 at 9:57
  • in my case, jq '.[] | sort_by(.storedBytes) | .[] | select(has("retentionInDays")|not)' has worked for a payload like: ``` { "logGroups": [ { "logGroupName": "/aws-glue/crawlers", "retentionInDays": 1234 }, { "logGroupName": "/aws/ecs/application/metrics" } ] } ```
    – Jose Alban
    Commented May 1 at 14:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.