
# Section: regex
# ___x_cmd_str_REGEX_SEP="$(printf "\001")"
___x_cmd_str_regex(){
    # Only dash does not support pattern="${pattern//\\/\\\\}"
    awk -v FS="${___x_cmd_str_REGEX_SEP}" '{
        if (match($1, $2))  exit 0
        else                exit 1
    }' <<A
${1}${___x_cmd_str_REGEX_SEP}${2:?___x_cmd_str_regex(): Provide pattern}
A
}


## Regular Expression design

export OR="\|"

R_wrap(){
    printf "%s" "\($1\)"
}

R_or(){
    R_wrap "$(___x_cmd_str_join "\|" "$@")"
}

# IP_0_255="[0-9]${OR}\([1-9][0-9]\)${OR}\(1[0-9][0-9]\)${OR}\(2[0-4][0-9]\)${OR}\(25[0-5]\)"

# shellcheck disable=SC2046,SC2006
# IP_0_255=$( R_or `R_wrap "[0-9]"` `R_wrap "[1-9][0-9]"` `R_wrap "1[0-9][0-9]"` `R_wrap "2[0-4][0-9]"` `R_wrap "25[0-5]"` )
# export IP="\\b${IP_0_255}\.${IP_0_255}\.${IP_0_255}\.${IP_0_255}\\b"

# [[:alpha:]] [[:alphanum:]] [[:number:]]
## EndSection
