RegExp

This formatter parses a message using a regular expression, performs string (template) replacement and returns the result.

Parameters

Posix

Set to true to compile the regular expression using posix semantics. By default this parameter is set to true.

Expression

Defines the regular expression used for parsing. For details on the regexp syntax see https://golang.org/pkg/regexp/syntax. By default this parameter is set to “(.*)”

Template (default: ${1})

Defines the result string. Regexp matching groups can be referred to using “${n}”, with n being the group’s index. For other possible reference semantics, see https://golang.org/pkg/regexp/#Regexp.Expand. By default this parameter is set to “${1}”

Parameters (from core.SimpleFormatter)

Source

This value chooses the part of the message the data to be formatted should be read from. Use “” to target the message payload; other values specify the name of a metadata field to target. By default this parameter is set to “”.

Target

This value chooses the part of the message the formatted data should be stored to. Use “” to target the message payload; other values specify the name of a metadata field to target. By default this parameter is set to “”.

ApplyTo

Use this to set Source and Target to the same value. This setting will be ignored if either Source or Target is set to something else but “”. By default this parameter is set to “”.

SkipIfEmpty

When set to true, this formatter will not be applied to data that is empty or - in case of metadata - not existing. By default this parameter is set to false

Examples

This example extracts time and host from an imaginary log message format.

exampleConsumer:
  Type: consumer.Console
  Streams: stding
  Modulators:
    - format.RegExp:
      Expression: "^(\\d+) (\\w+): "
      Template: "time: ${1}, host: ${2}"