Regex extract

Supported in: Batch, Streaming

Extracts the specified group from a regex. Returns empty string when no match is found.

Expression categories: Regex, String

Declared arguments

  • Expression - The expression to extract from.
    Expression<String>
  • Group - The group to extract from the regex match.
    Literal<Integer>
  • Pattern - The regex pattern to match.
    Expression<String>

Output type: String

Examples

Example 1: Base case

Description: Extract the first two initials from the first match. Argument values:

  • Expression: MT-112, XB-967
  • Group: 1
  • Pattern: (\w\w)(-)

Output: MT


Example 2: Base case

Argument values:

  • Expression: MT-112, XB-967
  • Group: 0
  • Pattern: NOT_FOUND

Output: empty string


Example 3: Null case

Description: Null inputs give null outputs. Argument values:

  • Expression: null
  • Group: 1
  • Pattern: (\w\w)(-)

Output: null