bash operator: =~ equal tilde operator

This is a wiki page. Be bold and improve it!

If you have any questions about the content on this page, don't hesitate to open a new ticket and we'll do our best to assist you.

The operator =~ is used in if-constructs to test a variable against a regular expression.

#!/bin/bash

if ! [[ "$1" =~ [^a-zA-Z0-9] ]]; then
  echo "$1 is NOT alphanumeric."
else
  echo "$1 is alphanumeric"
fi