diff --git a/SC2076.md b/SC2076.md index 6ebed34..3e65c63 100644 --- a/SC2076.md +++ b/SC2076.md @@ -3,20 +3,20 @@ ### Problematic code: ```sh -[[ $foo =~ "^fo+bar$" ]] +[[ $foo =~ "^fo+ bar$" ]] ``` ### Correct code: ```sh -[[ $foo =~ ^fo+bar$ ]] +[[ $foo =~ ^fo+\ bar$ ]] ``` ### Rationale: Quotes on the right hand side of `=~` can be used to match literally, so that `[[ $1 =~ ^"$2".* ]]` works even if `$2` contains regex metacharacters. This mirrors the behavior of globs, `[[ $1 = "$2"* ]]`. -This also means that the problematic code tries to match literal carets and plus signs instead of interpreting them as regular expression matchers. To match as a regex, it must be unquoted. +This also means that the problematic code tries to match literal carets and plus signs instead of interpreting them as regular expression matchers. To match as a regex, the regex metacharacters it must be unquoted. Literal parts of the expression can be quoted with double or single quotes, or escaped. ### Exceptions: