Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

jq negative select elements of array

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"]

like image 223
Konrads Avatar asked May 09 '18 14:05

Konrads


1 Answers

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))
like image 88
peak Avatar answered Oct 19 '22 16:10

peak