Sample Header Ad - 728x90

How to refer to matched groups in jq gsub?

9 votes
1 answer
6720 views
Using jq, I want to search for a pattern via regex, and wrap the **matched** string with something like
tags
$ echo "\"This is a valid json file"\" | jq '. | gsub("valid";"how_to_refer_to_matches";"i") -
How to refer to the matched results in the second argument of gsub? What if there are more than 1 matches?
Asked by Zeta.Investigator (1190 rep)
Jul 9, 2021, 06:46 PM
Last activity: Jul 9, 2021, 07:50 PM