Replaces each substring of the specified fields value that matches the given regular expression with the given replacement. LogScale uses JitRex which closely follows the syntax of re2j regular expressions, which has a syntax very close to Java's regular expressions. Check out the syntax.

asstringfalse Specifies the field to store the replaced string as. Default is replacing the contents of the input field.
fieldstringfalse@rawstringSpecifies the field to run the replacement on.
flagsstringfalsemSpecifies other regex flags.
  Valid ValuesdPeriod (.) includes newline characters
   iIgnore case for matched values
   mMulti-line parsing of regular expressions
regexstringtrue The regular expression to match. [a]
replacementstringfalse""The string to substitute for each match (same as with).
withstringfalse""The string to substitute for each match.

[a] If an argument name is not given, regex is the default argument.

replace() Examples

  • Correct a spelling mistake

    replace(regex=propperties, with=properties)
  • Get the integer part of a number. This example uses regex capturing groups, and stores the replacement in the field b, leaving field a untouched. This is the same as using a named capture group, for example:

    replace("(\\d+)\\..*", with="$1", field=a, as=b)
  • Truncate a message to 100 characters:

    replace("^(.{100}).*", with="$1", field=message, as="truncated_message")