跳转至

Regex extract(正则提取(Regex extract))

Supported in: Batch, Faster, 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\
  • Group: The group to extract from the regex match.
    Literal\
  • Pattern: The regex pattern to match.
    Expression\

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: Base case

Argument values:

  • Expression: zzzzhello hellozzzz
  • Group: 1
  • Pattern: (hello) \1

Output: hello


Example 4: Base case

Argument values:

  • Expression: helloworld
  • Group: 1
  • Pattern: (\w+)(?=world)

Output: hello


Example 5: Null case

Description: Null inputs give null outputs.

Argument values:

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

Output: null



中文翻译


正则提取(Regex extract)

支持:批处理(Batch)、快速处理(Faster)、流处理(Streaming)

从正则表达式中提取指定分组。未找到匹配项时返回空字符串。

表达式类别: 正则(Regex)、字符串(String)

声明的参数

  • 表达式(Expression): 用于提取的源表达式。
    表达式\<String>
  • 分组(Group): 从正则匹配结果中提取的分组编号。
    字面量\<Integer>
  • 模式(Pattern): 用于匹配的正则表达式模式。
    表达式\<String>

输出类型: String

示例

示例1:基础情况

描述: 提取第一个匹配项中的前两个首字母。

参数值:

  • 表达式: MT-112, XB-967
  • 分组: 1
  • 模式: (\w\w)(-)

输出: MT


示例2:基础情况

参数值:

  • 表达式: MT-112, XB-967
  • 分组: 0
  • 模式: NOT_FOUND

输出: 空字符串


示例3:基础情况

参数值:

  • 表达式: zzzzhello hellozzzz
  • 分组: 1
  • 模式: (hello) \1

输出: hello


示例4:基础情况

参数值:

  • 表达式: helloworld
  • 分组: 1
  • 模式: (\w+)(?=world)

输出: hello


示例5:空值情况

描述: 空输入产生空输出。

参数值:

  • 表达式: null
  • 分组: 1
  • 模式: (\w\w)(-)

输出: null