gpt4 book ai didi

regex - bash 中的@(...|...|...) 语法是什么?

转载 作者:行者123 更新时间:2023-11-29 08:59:50 25 4
gpt4 key购买 nike

关注此 question 中提到的 @() 语法:

[[ $OSTYPE == *@(darwin|freebsd|solaris|cygwin|openbsd)* ]]

这个语法从何而来?为什么在这种情况下使用它?和 有什么区别:

[[ $OSTYPE =~ (darwin|freebsd|solaris|cygwin|openbsd) ]]

[[ $OSTYPE == *(darwin|freebsd|solaris|cygwin|openbsd) ]]

这一切似乎都是等价的。

是否使用此语法代替 =~ 运算符以提高正则表达式的可移植性?

谢谢你的解释

最佳答案

man bash 中搜索 extglob 选项:

If the extglob shell option is enabled using the shopt builtin, several extended pattern matching operators are recognized. In the following description, a pattern-list is a list of one or more patterns separated by a |. Composite patterns may be formed using one or more of the following sub-patterns:

?(pattern-list)
Matches zero or one occurrence of the given patterns
*(pattern-list)
Matches zero or more occurrences of the given patterns
+(pattern-list)
Matches one or more occurrences of the given patterns
@(pattern-list)
Matches one of the given patterns
!(pattern-list)
Matches anything except one of the given patterns

关于regex - bash 中的@(...|...|...) 语法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35812293/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com