Updated SC2076 (markdown)

koalaman
2016-01-13 12:55:51 -08:00
parent 048b94f579
commit 93e96e7289

@@ -9,14 +9,14 @@
### 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: