Regex pattern for use with the =~ operator in [[ ]] test expressions.
Unlike regular words, regex patterns preserve metacharacters like [, ], (, ),
{, }, |, *, +, ?, ^, $, and . as literal regex syntax rather than
interpreting them as shell glob patterns or operators.
Examples
# [[ "hello123" =~ [0-9]+ ]]
%RegexPattern{
parts: [literal: "[0-9]+"]
}
# [[ "$str" =~ ^${prefix}[0-9]+$ ]]
%RegexPattern{
parts: [
{:literal, "^"},
{:variable, %AST.Variable{name: "prefix"}},
{:literal, "[0-9]+$"}
]
}BASH_REMATCH
When a regex pattern matches, the BASH_REMATCH array is populated:
BASH_REMATCH[0]contains the entire matchBASH_REMATCH[1..n]contain capture group matches
When the pattern does not match, BASH_REMATCH is unset.
Summary
Types
@type t() :: %Bash.AST.RegexPattern{ meta: Bash.AST.Meta.t(), parts: [Bash.AST.Word.part()] }