STRING1 =~ STRING2 (conditional operator)
true
if the value on the left matches the regular expression on the right.
=~
is not included in POSIX.
Avoid it if you want to stay compatible with POSIX shells.
Links
Examples
- Different ways to test if a string matches a regular expression:
1 2
# Bash [[ $name =~ J[au]ne ]] && echo "it's Jane or June!"
BashSupport Pro 是一个 支持 =~ 的 Bash 集成开发工具 – 马上试用!