14

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

22

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)) 
Sign up to request clarification or add additional context in comments.

5 Comments

But then the output is just true/false rather than the value tested
Surely you jest. Or maybe you misplaced a parenthesis?
he was refering to a filter, that is then popped into the correct select
@Hvisage - In jq, all “functions” are filters.
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" } ] } ```

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.