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.

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 is a Bash IDE with support for =~try it now!
© 2020–2024 Joachim Ansorg
Imprint
Privacy Policy
Legal