Kha*_*eal -1 string bash character
我想从用户那里收到一个字符串(一个单词),它应该通过以下标准:字符串可能只包含字母字符(aA-zZ)和下划线.不允许任何其他数字.我怎么能用bash做到这一点?
使用=~
要检查一个(POSIX扩展)正则表达式的字符串.请参阅联机帮助页bash(1)
以及regex(7)
更多信息.
# assume your string is in variable $s
if [[ $s =~ ^[A-Za-z_]+$ ]]; then
# it matches
else
# doesn't match
fi
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
11639 次 |
最近记录: |