zed icon indicating copy to clipboard operation
zed copied to clipboard

Creating record fields from regex named captures

Open zmajeed opened this issue 1 year ago • 8 comments

Is there a way to add a field with RE2 named capture groups?

zq -Z '/total (?P<total>\S+)/' - <<EOF
{
  msg: "total 27"
}
EOF

Output is

{
  msg: "total 27"
}

But I'd like to have

{
  msg: "total 27",
  total: "27"
}

And not need to do

zq -Z 'total:=regexp(/total (\S+)/, msg)[1]' - <<EOF
{
  msg: "total 27"
}
EOF

{
  msg: "total 27",
  total: "27"
}

zmajeed avatar Nov 28 '23 14:11 zmajeed