Updated on 2025-09-07 GMT+08:00

Regular Expression Function

This section describes regular expression functions, including their syntax, parameters, and usage examples.

Type

Function

Description

Value extraction

regex_select

Extracts values that meet regular expression conditions.

regex_findall

Obtains a list of all values that meet regular expression conditions.

Matching judgment

regex_match

Checks whether a regular expression is matched.

Replacement

regex_replace

Replaces a specified character in a string based on regular expressions.

Splitting

regex_split

Splits a string into string arrays.

regex_select

  • Function format
    regex_select(value, r"regular expression", mi=None, gi=None)
  • Parameter description

    Parameter

    Type

    Mandatory

    Description

    value

    Any

    Yes

    Value to be matched.

    regular expression

    String

    Yes

    Regular expression to be matched.

    mi

    int

    No

    Specifies the sequence number of the matched expression. The default value is None, indicating the first expression.

    gi

    int

    No

    Specifies the sequence number of the matched group. The default value is None, indicating the first group.

  • Returned result

    The extracted value.

  • Function example
    1. Example 1: Extract the first value that matches the regular expression from the str field.
      • Test data
        {
          "str": "iZbp1a65x3r1vhpe94fi2qZ"
        }
      • Processing rule
        e_set("regex", regex_select(v("str"), r"\d+"))
        e_set("regex2", regex_select(v("str"), r"\d+", mi=None))
        e_set("regex3", regex_select(v("str"), r"\d+", mi=0))
      • Processing result
        regex:1
        regex2:1
        regex3:1
        str:iZbp1a65x3r1vhpe94fi2qZ
    2. Example 2: Extract the first and second values that match the regular expression from the str field.
      • Test data
        {
          "str": "abc123 xyz456"
        }
      • Processing rule
        # Extract the first value that meets regular expression conditions from the field str.
        e_set("regex", regex_select(v("str"), r"\d+"))
        # Extract the second value that meets regular expression conditions from the field str.
        e_set("regex2", regex_select(v("str"), r"\d+", mi=1))
      • Processing result
        regex:   123
        regex2:  456
        str: abc123 xyz456
    3. Example 3: Extract the values of different groups of different expressions from the field str.
      • Test data
        {
          "str": "abc123 xyz456"
        }
      • Processing rule
        # Extract the value of the first group of the first expression that meets the regular expression from the field str.
        e_set("regex", regex_select(v("str"),r"[a-z]+(\d+)",gi=0))
        # Extract the value of the first group of the second expression that meets the regular expression from the field str.
        e_set("regex2", regex_select(v("str"),r"[a-z]+(\d+)",mi=1,gi=0))
        # Extract the value of the first group of the first expression that meets the regular expression from the field str.
        e_set("regex3", regex_select(v("str"),r"([a-z]+)(\d+)",gi=0))
        # Extract the value of the second group of the first expression that meets the regular expression in the str field.
        e_set("regex4", regex_select(v("str"),r"([a-z]+)(\d+)",gi=1))
      • Processing result
        str: abc123 xyz456 
        regex:   123
        regex2:  456
        regex3:  abc 
        regex4:  123

regex_findall

Use the regex_findall function to obtain a list of all values that meet regular expression conditions.

  • Function format
    regex_findall(value, r"regular expression")
  • Parameter description

    Parameter

    Type

    Mandatory

    Description

    value

    Any

    Yes

    Value to be matched.

    regular expression

    String

    Yes

    Regular expression.

  • Returned result

    The list that meets the search criteria.

  • Function example

    Obtain all digits in the str field.

    • Test data
      {
        "str": "iZbp1a65x3r1vhpe94fi2qZ"
      }
    • Processing rule
      e_set("regex_findall", regex_findall(v("str"),r"\d+"))
    • Processing result
      str: iZbp1a65x3r1vhpe94fi2qZ 
      regex_findall:  ["1", "65", "3", "1", "94", "2"]

regex_match

Use the regex_match function to check whether a regular expression is matched.

  • Function format
    regex_match(value, r"regular expression", full=false)
  • Parameter description

    Parameter

    Type

    Mandatory

    Description

    value

    Any

    Yes

    Value to be matched.

    regular expression

    String

    Yes

    Regular expression.

    full

    Bool

    No

    Whether the match is exact. The default value is false.

  • Returned result

    true or false.

  • Function example

    Check whether the field str contains digits.

    • Test data
      {
        "str": "iZbp1a65x3r1vhpe94fi2qZ"
      }
    • Processing rule
      # Check whether the str field contains digits.
      e_set("regex_match", regex_match(v("str"),r"\d+"))
      # Check whether the str field contains only digits.
      e_set("regex_match2", regex_match(v("str"),r"\d+",full=true))
    • Processing result
      str: iZbp1a65x3r1vhpe94fi2qZ 
      regex_match:  true
      regex_match2:  false

regex_replace

Use the regex_replace function to replace a specified character in a string based on regular expressions.

  • Function format
    regex_replace(value, r"regular expression", replace="", count=0)
  • Parameter description

    Parameter

    Type

    Mandatory

    Description

    value

    Any

    Yes

    Value to be replaced.

    regular expression

    String

    Yes

    Regular expression.

    replace

    String

    No

    New character. The default value is empty, indicating that characters are deleted.

    Regular expressions are supported. For example, r"\1****\2" indicates that the new string must match the regular expression.

    • \1 indicates the first group.
    • \2 indicates the second group.

    count

    Number

    No

    Number of replacement times. The default value is 0, indicating that all characters are replaced.

  • Returned result

    New string after replacement.

  • Function example
    1. Example 1: Replace all digits in str with 13.
      • Test data
        {
         "str": "iZbp1a65x3r1vhpe94fi2qZ ",
         "replace": "13"
        }
      • Processing rule
        e_set("regex_replace", regex_replace(v("str"),r"\d+",v("replace")))
      • Processing result
        str: iZbp1a65x3r1vhpe94fi2qZ 
        replace: 13
        regex_replace:  iZbp13a13x13r13vhpe13fi13qZ
    2. Example 2: Anonymize the middle four digits of a mobile number.
      • Test data
        {
         "iphone": "13900001234"
        }
      • Processing rule
        • replace=r"\1****\2" indicates that the string after replacement must meet the regular expression r"\1****\2".
        • \1 indicates the first group, that is, (\d{0,3}).
        • \2 indicates the second group, that is, (\d{4}).
        e_set(
            "sec_iphone",
            regex_replace(v("iphone"), r"(\d{0,3})\d{4}(\d{4})", replace=r"\1****\2"),
        )
      • Processing result
        iphone: 13900001234
        sec_iphone: 139****1234

regex_split

Use the regex_split function to split a string into string arrays.

  • Function format
    regex_split(value, r"regular expression", maxsplit=0)
  • Parameter description

    Parameter

    Type

    Mandatory

    Description

    value

    Any

    Yes

    Value to be split.

    regular expression

    String

    Yes

    Regular expression.

    maxsplit

    int

    No

    Maximum number of split matching times. The default value is 0, indicating that all matching items are split. If the value is 1, only the first match item is split.

  • Returned result

    The split array list.

  • Function example

    Split the str field by digit.

    • Test data
      {
        "str": "iZbp1a65x3r1vhpe94fi2qZ"
      }
    • Processing rule
      e_set("regex_split", regex_split(v("str"),r"\d+"))
    • Processing result
      str: iZbp1a65x3r1vhpe94fi2qZ 
      regex_split:  ["iZbp", "a", "x", "r", "vhpe", "fi", "qZ"]