Bash - Regex

Bash Liste Des Attaques Ovh

Bash - Regex


Multilingual Regular Expression Syntax (Pattern) in Bash



[[ "$tomatch" =~ '/php-status' ]] && echo match
[[ ! "$tomatch" =~ 'not' ]] && echo does not match

Group Capture

Group capture


# double bracket is mandatory
if [[ $f =~ $regex ]]
	echo "${name}.jpg"    # concatenate strings
	name="${name}.jpg"    # same thing stored in a variable
	echo "$f doesn't match" >&2 # this could get noisy if there are a lot of non-matching files

Bash Binary operator

When the additional regexp binary operator =~ is used, the string to the right of the operator is considered an extended regular expression and matched accordingly.

The operator has the same precedence as == and !=

The return value is:

  • 0 if the string matches the pattern
  • 2 if the regular expression is syntactically incorrect
  • 1 otherwise.


  • If the shell option nocasematch is enabled, the match is performed without regard to the case of alphabetic characters.
  • Any part of the pattern may be quoted to force it to be matched as a string.
  • Capturing group are saved in the BASH_REMATCH variable.


Note that pathname expansion use globbing as well as the control flow structure such as case


Recommended Pages
Bash Liste Des Attaques Ovh
Bash - Case

The case control statement execute commands based on regular expression pattern matching. Initscript example: Selectively execute COMMANDS based upon WORD matching glob PATTERN. The | is used to...
Bash Liste Des Attaques Ovh
Bash - Password

password in bash Snippet to test the complexity of the password with: regexp and the and && operator
Bash Liste Des Attaques Ovh
Sh - String Variable

String Variable, see also character string in bash. When calling a function, quote the variable otherwise bash will not see the string as atomic but as an array Sh with Bash “” The...

Share this page:
Follow us:
Task Runner