Redian新闻
>
a question about regular expression
avatar
a question about regular expression# Unix - 噫吁兮,危乎高哉
w*c
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
avatar
x*i
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

avatar
w*c
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..:)

avatar
w*n
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.
avatar
x*i
5
read carefully.. vim(vi iMprovement) is not vi..

【在 w****c 的大作中提到】
: sorry, seems not work well.
相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。