Skip to content

Commit

Permalink
docs: clarify rules around escaping backslashes in YAML
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
Rate limit · GitHub

Access has been restricted

You have triggered a rate limit.

Please wait a few minutes before you try again;
in some cases this may take up to an hour.

rfratto committed Jan 28, 2020
1 parent f7ad6a1 commit 88b04cc
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
@@ -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`

0 comments on commit 88b04cc

Please sign in to comment.