xpt
xpt

Reputation: 22994

AWK - replace with sub match

How to use awk to do replacing with sub match?

I tried:

{
fss="FieldsFunc(s string, f bool)"
fss=gensub(/([( ])(.+?) .+?([,)])/,"\\1\\2\\3","g",fss); print fss;
}

and am expecting the output to be FieldsFunc(s, f), but I got FieldsFunc(s string, f). What I've done wrong? Thx.

Upvotes: 0

Views: 260

Answers (1)

revo
revo

Reputation: 48711

g?awk doesn't have support for lazniness. Ungreedy quantifiers are Perl specific. You could change your regex to some thing more restrictive:

fss = gensub(/(\w+) +\w+([,)])/,"\\1\\2", "g", fss);

Upvotes: 1

Related Questions