跳转至

Regex replace(正则替换(Regex replace))

Supported in: Batch, Faster, Streaming

Replace a string using a regex pattern.

Expression categories: Regex, String

Declared arguments

  • Expression: Input string to replace.
    Expression\
  • Pattern: The regex pattern to match.
    Expression\
  • Replace: Replacement string.
    Expression\

Output type: String

Examples

Example 1: Base case

Argument values:

  • Expression: tail_number
  • Pattern: (\w\w)(-)
  • Replace: **-
tail_number Output
MT-123 **-123
XB-434 **-434
MT-123, XB-434 **-123, **-434

Example 2: Base case

Argument values:

  • Expression: tail_number
  • Pattern: \
  • Replace: \\
tail_number Output
this is a backslash \ etc this is a backslash \ etc

Example 3: Base case

Argument values:

  • Expression: path
  • Pattern: \
  • Replace: /
path Output
path\to\file path/to/file
C:\Users\John C:/Users/John

Example 4: Base case

Argument values:

  • Expression: price
  • Pattern: $
  • Replace: USD
price Output
Price is $50 Price is USD 50
$100 and $200 USD 100 and USD 200

Example 5: Base case

Argument values:

  • Expression: price
  • Pattern: $(\d+)
  • Replace: $1 dollars
price Output
I have $100 I have 100 dollars
$50 and $75 50 dollars and 75 dollars

Example 6: Base case

Argument values:

  • Expression: tail_number
  • Pattern: (\w\w)(-)
  • Replace: \
tail_number Output
MT-123 \123
XB-434 \434
MT-123, XB-434 \123, \434

Example 7: Base case

Argument values:

  • Expression: text
  • Pattern: foo
  • Replace: \$
text Output
foo $
foo bar foo $ bar $

Example 8: Base case

Argument values:

  • Expression: tail_number
  • Pattern: (\w\w)(-)
  • Replace: $
tail_number Output
MT-123 $123
XB-434 $434
MT-123, XB-434 $123, $434

Example 9: Base case

Argument values:

  • Expression: tail_number
  • Pattern: (\w\w)(-)
  • Replace: $1
tail_number Output
MT-123 MT123
XB-434 XB434
MT-123, XB-434 MT123, XB434

Example 10: Null case

Argument values:

  • Expression: tail_number
  • Pattern: regex
  • Replace: foo
tail_number regex Output
MT-123 ( null

Example 11: Null case

Description: Null inputs give null outputs.

Argument values:

  • Expression: null
  • Pattern: (\w\w)(-)
  • Replace: **

Output: null


Example 12: Null case

Description: Null inputs give null outputs.

Argument values:

  • Expression: foo
  • Pattern: bar
  • Replace: null

Output: null



中文翻译


正则替换(Regex replace)

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

使用正则表达式模式替换字符串。

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

声明的参数

  • 表达式(Expression): 待替换的输入字符串。
    表达式\<String>
  • 模式(Pattern): 用于匹配的正则表达式模式。
    表达式\<String>
  • 替换内容(Replace): 替换字符串。
    表达式\<String>

输出类型: String

示例

示例 1:基础案例

参数值:

  • 表达式: tail_number
  • 模式: (\w\w)(-)
  • 替换内容: **-
tail_number 输出
MT-123 **-123
XB-434 **-434
MT-123, XB-434 **-123, **-434

示例 2:基础案例

参数值:

  • 表达式: tail_number
  • 模式: \
  • 替换内容: \\
tail_number 输出
this is a backslash \ etc this is a backslash \ etc

示例 3:基础案例

参数值:

  • 表达式: path
  • 模式: \
  • 替换内容: /
path 输出
path\to\file path/to/file
C:\Users\John C:/Users/John

示例 4:基础案例

参数值:

  • 表达式: price
  • 模式: $
  • 替换内容: USD
price 输出
Price is $50 Price is USD 50
$100 and $200 USD 100 and USD 200

示例 5:基础案例

参数值:

  • 表达式: price
  • 模式: $(\d+)
  • 替换内容: $1 dollars
price 输出
I have $100 I have 100 dollars
$50 and $75 50 dollars and 75 dollars

示例 6:基础案例

参数值:

  • 表达式: tail_number
  • 模式: (\w\w)(-)
  • 替换内容: \
tail_number 输出
MT-123 \123
XB-434 \434
MT-123, XB-434 \123, \434

示例 7:基础案例

参数值:

  • 表达式: text
  • 模式: foo
  • 替换内容: \$
text 输出
foo $
foo bar foo $ bar $

示例 8:基础案例

参数值:

  • 表达式: tail_number
  • 模式: (\w\w)(-)
  • 替换内容: $
tail_number 输出
MT-123 $123
XB-434 $434
MT-123, XB-434 $123, $434

示例 9:基础案例

参数值:

  • 表达式: tail_number
  • 模式: (\w\w)(-)
  • 替换内容: $1
tail_number 输出
MT-123 MT123
XB-434 XB434
MT-123, XB-434 MT123, XB434

示例 10:空值案例

参数值:

  • 表达式: tail_number
  • 模式: regex
  • 替换内容: foo
tail_number regex 输出
MT-123 ( null

示例 11:空值案例

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

参数值:

  • 表达式: null
  • 模式: (\w\w)(-)
  • 替换内容: **

输出: null


示例 12:空值案例

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

参数值:

  • 表达式: foo
  • 模式: bar
  • 替换内容: null

输出: null