[jq] Test whether a string matches a regular expression

Created on November 30, 2026

Use test to return true or false for a regular expression match. The caret in ^error: anchors that pattern to the beginning of the string.

printf '%s\n' '"error: connection failed"' '"info: connected"' | jq 'test("^error:")'
true
false

Pass the second argument "i" to make the check case-insensitive.

printf '%s\n' '"ERROR: connection failed"' | jq 'test("^error:"; "i")'
true

The uppercase input in the second example returns false if you omit the flag.

Reference

jq