Bash:RegularExpressions
lastmod 2026-11-10created 2022-06-153 edits
Regular expressions in Bash are a feature that compares a string against a POSIX extended regular expression (ERE) with the =~ operator inside a [[ ]] conditional expression. The pattern must be written without quotes to be interpreted as a regular expression, and the matches of parenthesized groups go into the BASH_REMATCH array, so you can extract substrings. Unlike the case statement or == comparison, which only use glob patterns, it allows quantifiers and character classes, making it useful for input validation.