Question

I really though I had it when I tried s/^\(K_.+\):\("."\),/myvars\.setvar(\1,\2)/g

I have a 100 lines or so like K_KP4:"4" that I want to change

I think the problem is \1 \2 refer to different instances of the same grouping pattern, which means ID'ing 2 different groups in a vi regex is impossible???

no luck with sed

isn't there a way of having a name capturing group, something like a=>(K_.+) ?

Was it helpful?

Solution

In vi(m) regex, you need to escape the + to make it act as a metacharacter.

:%s/^\(K_.\+\):\("."\)/myvars.setvar(\1,\2)/

Also, the g flag for :s means Replace all instances on this line. If there is truly one instance per line, as your post suggests, then the g is unnecessary and you instead need to specify that the command should run on all lines in the file -- :%s/...

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top