diff --git a/builtin.c b/builtin.c index ddd207b3..0629ca99 100644 --- a/builtin.c +++ b/builtin.c @@ -1057,9 +1057,7 @@ static const char* const jq_builtins[] = { // # create the \"capture\" object: " | reduce ( $r | .captures | .[] | select(.name != null) | { (.name) : .string } ) as $pair" " ({}; . + $pair)" - " | if . == {} then $in | .[0:$r.offset]+s+.[$r.offset+$r.length:]" - " else (. | s)" - " end" + " | $in[0:$r.offset] + s + $in[$r.offset+$r.length:]" " end ;", // // repeated substitution of re (which may contain named captures) diff --git a/tests/all.test b/tests/all.test index 84d4491d..c4c3b0df 100644 --- a/tests/all.test +++ b/tests/all.test @@ -859,6 +859,10 @@ capture("(?[a-z]+)-(?[0-9]+)") ["a,b, c, d, e,f", ", a,b, c, d, e,f, "] ["a,b:c, d, e,f",":a,b, c, d, e,f, "] +sub("^(?.)"; "Head=\(.head) Tail=") +"abcdef" +"Head=a Tail=bcdef" + [.[] | gsub(", "; ":")] ["a,b, c, d, e,f",", a,b, c, d, e,f, "] ["a,b:c:d:e,f",":a,b:c:d:e,f:"]