英文:
C-Shell regex compare a variable with two strings
问题
这返回1:
if ( "$TERM" =~ "xterm*" ) echo 1
但这些返回空值:
if ( "$TERM" =~ "(xterm*|rxvt*)" ) echo 1
if ( "$TERM" =~ "(xterm|rxvt)*" ) echo 1
我应该如何在csh中执行OR正则比较?提前感谢。
英文:
This returns 1:
if ( "$TERM" =~ "xterm*" ) echo 1
but these return nothing:
if ( "$TERM" =~ "(xterm*|rxvt*)" ) echo 1
if ( "$TERM" =~ "(xterm|rxvt)*" ) echo 1
How am I supposed to do OR regex comparisons in csh? Thanks in advance.
答案1
得分: 2
C-Shell
中 =~
运算符的右操作数不是正则表达式模式,而是通配符模式。
从此文档中找到:
">=~
和 !~
运算符类似于 !=
和 ==
,不同之处在于右侧是一个通配符模式(参见文件名替代),与左侧操作数进行匹配。"
英文:
The right-hand operand in C-Shell's =~
operator is not a RegEx pattern but a glob pattern.
From this documentation I found:
>The operators '=~' and '!~' are like '!=' and '==' except that the right hand side is a glob-pattern (see Filename substitution) against which the left hand operand is matched.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论