JQ Recipes

regex

jq uses the Oniguruma regular expression library

Match  
Positive lookahead ?=
Negative lookahead ?!
Positive lookbehind ?<=
Negative lookbehind ?<!
Extended groups

  i: ignore case
  m: multi-line (dot (.) also matches newline)
  x: extended form
  W: ASCII only word (\w, \p{Word}, [[:word:]])
     ASCII only word bound (\b)
  D: ASCII only digit (\d, \p{Digit}, [[:digit:]])
  S: ASCII only space (\s, \p{Space}, [[:space:]])
  P: ASCII only POSIX properties (includes W,D,S)
      (alnum, alpha, blank, cntrl, digit, graph,
      lower, print, punct, space, upper, xdigit, word)

  y{?}: Text Segment mode
    This option changes the meaning of \X, \y, \Y.
    Currently, this option is supported in Unicode only.

    y{g}: Extended Grapheme Cluster mode (default)
    y{w}: Word mode

Lookahead

Remove repeating characters

$ jq -n '"aaaabbbbcccc" | gsub("(.)(?=.*\\1)";"")'
"abc"

$ jq -n '"aaaabbbbccccaaaa" | gsub("(.)(?=.*\\1)";"")'
"bca"

Only remove first repeating 'a'

$ jq -n '"aaaabbbbcccc126186" | gsub("\\b(.)(?=.*\\1)";"")'
"abbbbcccc126186"
$ jq -n '"aaaa bbbb cccc 126 126" | gsub("(\\b.)(?=.*\\1)";"")'
"abc 126"

Resources: