Extract all regex matches(提取所有正则表达式匹配项)¶
Supported in: Batch, Faster, Streaming
Extract all instances of a regex match into an array.
Expression categories: Regex, String
Declared arguments¶
- Expression: String to extract values from.
Expression\ - Group: Group number to extract. If 0, the whole regex pattern is matched.
Literal\ - Pattern: The regex pattern to match.
Expression\
Output type: Array\
Examples¶
Example 1: Base case¶
Description: Extract the first two initials from each code.
Argument values:
- Expression: MT-112, XB-967
- Group: 1
- Pattern: (\w\w)(-)
Output: [ MT, XB ]
Example 2: Base case¶
Description: Extract all match groups, this includes first two initials and the dash.
Argument values:
- Expression: MT-112, XB-967
- Group: 0
- Pattern: (\w\w)(-)
Output: [ MT-, XB- ]
Example 3: Base case¶
Description: Extract the second match group if present.
Argument values:
- Expression: hel1o code 2 1
- Group: 2
- Pattern: ([0-9]+)\s*([a-z]*)
Output: [ o, empty string, empty string ]
Example 4: Base case¶
Description: Extract the second match group if present.
Argument values:
- Expression: hel1o code 2 1
- Group: 2
- Pattern: ([0-9]+)\s*([a-z]+)?
Output: [ o, empty string, empty string ]
Example 5: Base case¶
Description: Extract the pattern with no match group defined.
Argument values:
- Expression: this code[123]
- Group: 0
- Pattern: code[
Output: [ code[ ]
Example 6: Base case¶
Description: Extract the second match group.
Argument values:
- Expression: hel1o code 2 app
- Group: 2
- Pattern: ([0-9]+)\s*([a-z]+)
Output: [ o, app ]
Example 7: Base case¶
Description: Extract with backtracking.
Argument values:
- Expression: hello hello hello hello
- Group: 1
- Pattern: (hello) \1
Output: [ hello, hello ]
Example 8: Base case¶
Description: Extract with lookahead.
Argument values:
- Expression: helloworld goodbyeworld
- Group: 1
- Pattern: (\w+)(?=world)
Output: [ hello, goodbye ]
Example 9: Null case¶
Description: Null inputs give null outputs.
Argument values:
- Expression: null
- Group: 1
- Pattern: (\w\w)(-)
Output: null
中文翻译¶
提取所有正则表达式匹配项¶
支持环境:批处理(Batch)、快速处理(Faster)、流处理(Streaming)
将所有正则表达式匹配的实例提取到数组中。
表达式类别: 正则表达式(Regex)、字符串(String)
声明参数¶
- 表达式(Expression): 要提取值的字符串。
Expression\ - 分组(Group): 要提取的分组编号。如果为0,则匹配整个正则表达式模式。
Literal\ - 模式(Pattern): 要匹配的正则表达式模式。
Expression\
输出类型: Array\
示例¶
示例1:基础案例¶
描述: 从每个代码中提取前两个首字母。
参数值:
- 表达式(Expression): MT-112, XB-967
- 分组(Group): 1
- 模式(Pattern): (\w\w)(-)
输出: [ MT, XB ]
示例2:基础案例¶
描述: 提取所有匹配分组,包括前两个首字母和连字符。
参数值:
- 表达式(Expression): MT-112, XB-967
- 分组(Group): 0
- 模式(Pattern): (\w\w)(-)
输出: [ MT-, XB- ]
示例3:基础案例¶
描述: 提取第二个匹配分组(如果存在)。
参数值:
- 表达式(Expression): hel1o code 2 1
- 分组(Group): 2
- 模式(Pattern): ([0-9]+)\s*([a-z]*)
输出: [ o, 空字符串, 空字符串 ]
示例4:基础案例¶
描述: 提取第二个匹配分组(如果存在)。
参数值:
- 表达式(Expression): hel1o code 2 1
- 分组(Group): 2
- 模式(Pattern): ([0-9]+)\s*([a-z]+)?
输出: [ o, 空字符串, 空字符串 ]
示例5:基础案例¶
描述: 提取未定义匹配分组的模式。
参数值:
- 表达式(Expression): this code[123]
- 分组(Group): 0
- 模式(Pattern): code[
输出: [ code[ ]
示例6:基础案例¶
描述: 提取第二个匹配分组。
参数值:
- 表达式(Expression): hel1o code 2 app
- 分组(Group): 2
- 模式(Pattern): ([0-9]+)\s*([a-z]+)
输出: [ o, app ]
示例7:基础案例¶
描述: 使用回溯(backtracking)进行提取。
参数值:
- 表达式(Expression): hello hello hello hello
- 分组(Group): 1
- 模式(Pattern): (hello) \1
输出: [ hello, hello ]
示例8:基础案例¶
描述: 使用前瞻(lookahead)进行提取。
参数值:
- 表达式(Expression): helloworld goodbyeworld
- 分组(Group): 1
- 模式(Pattern): (\w+)(?=world)
输出: [ hello, goodbye ]
示例9:空值案例¶
描述: 空输入产生空输出。
参数值:
- 表达式(Expression): null
- 分组(Group): 1
- 模式(Pattern): (\w\w)(-)
输出: null