Skip to content

Commit

Permalink
docs: clarify rules around escaping backslashes in YAML (#1601)
Browse files Browse the repository at this point in the history
YAML treats backslashes in double-quoted strings differently than
backslashes in non-double-quoted strings. This commit clarifies the
behavior for the regex stage.

Closes #1597
  • Loading branch information
rfratto authored Jan 29, 2020
1 parent c793d7d commit 576e479
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions docs/clients/promtail/stages/regex.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,20 @@ will be set into the `extracted` map, every capture group **must be named:**
`(?P<name>re)`. The name of the capture group will be used as the key in the
extracted map.

Because of how YAML treats backslashes in double-quoted strings, note that all
backslashes in a regex expression must be escaped when using double quotes. For
example, all of these are valid:

- `expression: \w*`
- `expression: '\w*'`
- `expression: "\\w*"`

But these are not:

- `expression: \\w*` (only escape backslashes when using double quotes)
- `expression: '\\w*'` (only escape backslashes when using double quotes)
- `expression: "\w*"` (backslash must be escaped)

## Example

### Without `source`
Expand Down

0 comments on commit 576e479

Please sign in to comment.