加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

运算符 – VimScript中的??是什么意思?

发布时间:2020-12-15 18:47:22 所属栏目:安全 来源:网络整理
导读:我无法为我的生活找到一个答案,无论是在谷歌或这里或在帮助文件. if "test.c" =~ ".c" 起初我以为??平均结束了,但是观察这些结果: Command Resultecho "test.c" =~ ".c" 1echo "test.c" =~ ".pc" 0echo "test.pc" =~ ".c" 1echo "testc" =~ ".c" 1echo
我无法为我的生活找到一个答案,无论是在谷歌或这里或在帮助文件.
if "test.c" =~ ".c"

起初我以为??平均结束了,但是观察这些结果:

Command                               Result
echo "test.c" =~ ".c"                1
echo "test.c" =~ ".pc"               0
echo "test.pc" =~ ".c"               1
echo "testc" =~ ".c"                 1
echo "ctest" =~ ".c"                 1
echo "ctestp" =~ ".pc"               0
echo "pctestp" =~ ".pc"              0
echo ".pctestp" =~ ".pc"             0

一个很好的解释.指向尝试破译VimScript的站点的链接会更好.

From the Vim documentation,它在右边的操作数(作为一个模式)做一个模式匹配.

For strings there are two more items:

a =~ b      matches with
    a !~ b      does not match with

The left item “a” is used as a string. The right item “b” is used as a pattern,like what’s used for searching. Example:

:if str =~ " "
    :  echo "str contains a space"
    :endif
    :if str !~ '.$'
    :  echo "str does not end in a full stop"
    :endif

您可能会再次尝试您的测试用例.我得到了,例如,与你的不一致:

echo ".pctestp" =~ ".pc"             1

而双引号和单引号似乎会影响反斜杠的解释方式:

echo "test.pc" =~ ".c"               1
echo "test.pc" =~ '.c'               0

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读