shell script에서 때로는 문자열 패턴의 일치 여부를 확인하는 것이 아니라 포함되는지 확인해야 하는 경우가 있습니다.
아래 예시와 같습니다.
아래 두 가지 방법을 소개합니다.
An additional binary operator, =~, is available, with the same precedence as == and !=. When it is
used, the string to the right of the operator is considered an extended regular expression and matched
accordingly (as in regex(3)). The return value is 0 if the string matches the pattern, and 1 other-
wise. If the regular expression is syntactically incorrect, the conditional expression’s return value
is 2. 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.
Substrings matched by parenthesized subexpressions within the regular expression are saved in the array
variable BASH_REMATCH. The element of BASH_REMATCH with index 0 is the portion of the string matching
the entire regular expression. The element of BASH_REMATCH with index n is the portion of the string
matching the nth parenthesized subexpression.