w****c 发帖数: 10 | 1 one question about regular expression:
assuming we have statement as following:
%var1%/dir:%var2%/dir:%var3%/dir
in vi, it is expected that using s/%\(.*\)%/$\1/g the above
could be converted to "$var1/dir:$var2/dir:$var3/dir".but
I found that it wound up with "$var1%/dir:%var2%/dir:%var3/dir",
that is, vi searchs for largest matchup. How could I get the
fewest match up?
it is very interesting question. hope unix guru could help me.
Acton |
x*****i 发帖数: 253 | 2 does vi support non-greedy regex..? in vim.. u
can do s/%\(.\{-}\)%/$\1/g...
none of those regex engine
can reach the level Perl(c#) does..:)
【在 w****c 的大作中提到】 : one question about regular expression: : assuming we have statement as following: : %var1%/dir:%var2%/dir:%var3%/dir : in vi, it is expected that using s/%\(.*\)%/$\1/g the above : could be converted to "$var1/dir:$var2/dir:$var3/dir".but : I found that it wound up with "$var1%/dir:%var2%/dir:%var3/dir", : that is, vi searchs for largest matchup. How could I get the : fewest match up? : it is very interesting question. hope unix guru could help me. : Acton
|
w****c 发帖数: 10 | 3 sorry, seems not work well.
【在 x*****i 的大作中提到】 : does vi support non-greedy regex..? in vim.. u : can do s/%\(.\{-}\)%/$\1/g... : none of those regex engine : can reach the level Perl(c#) does..:)
|
w*****n 发帖数: 94 | 4 if vi does not support non-greedy regexp, try to use
[\w]* or [a-zA-Z0-9]* or [^%]* instead of .*
【在 w****c 的大作中提到】 : sorry, seems not work well.
|
x*****i 发帖数: 253 | 5 read carefully.. vim(vi iMprovement) is not vi..
【在 w****c 的大作中提到】 : sorry, seems not work well.
|