C-Shell正则表达式比较一个变量与两个字符串。

huangapple go评论64阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2023年5月24日 22:30:01
  • 转载请务必保留本文链接:https://go.coder-hub.com/76324640.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定