rex4j

This command is experimental

Definition

With rex4j command you can either extract data from columns based on a given regular expression, or replace characters in a column using sed expressions.

rex4j command is used in the same way as rex command, however rex4j is using Teragrep specific Java regex, so it is designed to be executed faster.

Syntax

| rex4j [field=<column-name>] ("<regex-expression>" [max_match=<integer>] [offset_field=<string>] | mode=sed "<sed-expression>")

Optional arguments

Examples

Use either a regular expression to extract data into a separate column or a sed expression to replace or substitute values that match with the regular expression.

To extract data, you can add only the regular expression after rex4j if you’re extracting from the _raw column.

index=sales_inventory earliest=-5y
| rex4j "(?<ID>\w{8}-\w{4}-\w{4}-\w{4}-\w{12})"
Screenshot of the previous example’s result

To replace values, use mode=sed and then add the sed expression.

| rex4j mode=sed "[s|y]/<regex-expression>/<replacement>/[g|Ng|N]"

In the sed expression:

  • s replaces strings

  • y replaces substitute characters

  • / is a delimiter

  • g replaces all

  • Ng replaces globally the Nth occurrence

  • N replaces the Nth occurrence

Only s/ and /g are currently supported in rex4j.

The following example uses sed expression to replace a certain ID with the product’s name for all matches.

index=sales_inventory earliest=-5y
| rex4j mode=sed "s/17d2d82a-2660-40bd-bde1-d0609a26a782/legendary book/g"
Screenshot of the previous example’s result

field

With field argument you can define which column you want to extract data from.

index=sales_inventory earliest=-5y
| rex4j field=_raw "(?<ID>\w{8}-\w{4}-\w{4}-\w{4}-\w{12})"
Screenshot of the previous example’s result

max_match

Currently not supported

You can specify the number of times the regex is matched. If max_match is greater than 1, the resulted columns will be multivalued. You can use 0 to define unlimited matches.

By default max_match is set as 1.

offset_field

Currently not supported

With offset_field you can create a separate column that lists the position of values defined by the user.

Further Reading