This topic describes the syntax and parameters of string functions. This topic also provides examples on how to use the functions.
Functions
Category | Function | Description |
---|---|---|
Multi-string operation | str_format | Formats strings. |
str_join | Concatenates input strings to generate a new string by using a specified connector. | |
str_zip | Concurrently splits two values or strings that are returned by expressions and combines the results into one string. | |
Encoding and decoding | str_encode | Encodes a string by using a specified encoding format. |
str_decode | Decodes an input value by using a specified encoding format. | |
str_hex_escape_encode | Escapes special characters. The function can escape hexadecimal characters to Chinese characters. | |
str_uuid | Generates a random UUID. | |
Sorting, reversing, and replacement | str_sort | Sorts a specified object. |
str_reverse | Reverses a string. | |
str_replace | Replaces an old string with a new string based on a specified rule. | |
str_logstash_config_normalize | Converts data in the Logstash configuration language to the JSON format. | |
str_translate | Replaces specified characters in a string with mapping characters. | |
Regular munging | str_strip | Deletes specified characters from a string. |
str_lstrip | Deletes specified characters from the start of a string. | |
str_rstrip | Deletes specified characters from the end of a string. | |
str_lower | Converts all uppercase letters in a string to lowercase letters. | |
str_upper | Converts all lowercase letters in a string to uppercase letters. | |
str_title | Capitalizes the first letter of each word in a string and converts the other letters in the string to lowercase letters. | |
str_capitalize | Capitalizes the first letter of a string and converts the other letters in the string to lowercase letters. | |
str_swapcase | Converts the uppercase letters into lowercase letters and lowercase letters into uppercase letters in a string. | |
Search and check | str_count | Counts the number of occurrences of a character in a string. |
str_find | Checks whether a string contains a specified substring. | |
str_rfind | Returns the position of the last occurrence of a specified string or a specified character in a string. | |
str_endswith | Checks whether a string ends with a specified suffix. | |
str_startswith | Checks whether a string starts with a specified string. | |
Splitting | str_split | Splits a string by using a specified delimiter. |
str_splitlines | Splits a string by using a line feed. | |
str_partition | Splits a string into three parts from left to right by using a specified delimiter. | |
str_rpartition | Splits a string into three parts from right to left by using a specified delimiter. | |
Formatting | str_center | Pads a string to a specified length by using a specified character. |
str_ljust | Pads a string to a specified length by using a specified character from the end of the string. | |
str_rjust | Pads a string to a specified length by using a specified character from the start of the string. | |
str_zfill | Pads a string to a specified length by using 0 from the start of the string. | |
str_expandtabs | Converts \t in a string to spaces.
|
|
Character set check | str_isalnum | Checks whether a string contains only letters and digits. |
str_isalpha | Checks whether a string contains only letters. | |
str_isascii | Checks whether a string is in the ASCII table. | |
str_isdecimal | Checks whether a string contains only decimal characters. | |
str_isdigit | Checks whether a string contains only digits. | |
str_isidentifier | Checks whether a string is a valid Python identifier or checks whether a variable name is valid. | |
str_islower | Checks whether a string contains lowercase letters. | |
str_isnumeric | Checks whether a string contains digits. | |
str_isprintable | Checks whether all characters in a string are printable characters. | |
str_isspace | Checks whether a string contains only spaces. | |
str_istitle | Checks whether the first letter of each word in a string is in upper case and the other letters in the string are in lower case. | |
str_isupper | Checks whether all letters in a string are in upper case. |
Category | Function | Description |
---|---|---|
Multi-string operation | op_add | Returns the sum value among multiple numeric values or strings. |
op_max | Returns the maximum value among multiple numeric values or strings. | |
op_min | Returns the minimum value among multiple numeric values or strings. | |
String truncation | op_slice | Truncates a string. |
Length calculation | op_len | Returns the length of a string. |
str_format
-
Syntax
str_format(format_string, value1, value2, ...)
-
Parameters
Parameter Type Required Description format_string Arbitrary (automatically converted to the string type) Yes The format of the output string. Example: {}={}
.value1 Arbitrary Yes The value that you want to format. value2 Arbitrary Yes The value that you want to format. -
Response
A formatted string is returned.
-
Examples
- Raw log:
class: Format escape_name: Traditional
- Transformation rule:
e_set("str_format", str_format("{}={}", v("class"), v("escape_name")))
- Result:
class: Format escape_name: Traditional str_format: Format=Traditional
- Raw log:
str_join
-
Syntax
str_join(connector, value1, value2, ....)
-
Parameters
Parameter Type Required Description connector Arbitrary (automatically converted to the string type) Yes The connector. Supported connectors include the exclamation point (!), at sign (@), number sign (#), dollar sign ($), and percent sign (%). value1 Arbitrary (automatically converted to the string type) Yes The value that you want to concatenate. value2 Arbitrary (automatically converted to the string type) Yes The value that you want to concatenate. -
Response
A concatenated string is returned.
-
Examples
- Raw log:
name: ETL company: aliyun.com
- Transformation rule:
e_set("email", str_join("@", v("name"), v("company")))
- Result:
name: ETL company: aliyun.com email:ETL@aliyun.com
- Raw log:
str_encode
-
Syntax
str_encode(value, "utf8", errors="ignore")
-
Parameters
Parameter Type Required Description value Arbitrary (automatically converted to the string type) Yes The value that you want to encode. encoding String No The encoding format. Default value: utf8. ASCII is supported. errors String No The method that is used to process characters if some characters cannot be recognized based on the encoding format. Valid values: - ignore: No characters are encoded. This is the default value.
- strict: An error is reported and the data of the log is discarded.
- replace: The unrecognized characters are replaced with question marks (?).
- xmlcharrefreplace: The unrecognized characters are replaced with XML characters.
-
Response
An encoded string is returned.
-
Examples
- Example 1
- Raw log:
test: asewds
- Transformation rule:
e_set("f1", str_decode(str_encode("hello", "utf8"), "utf8"))
- Result:
test: asewds f1: hello
- Raw log:
- Example 2
- Raw log:
f2: test test data
- Transformation rule:
e_set("f1", str_encode(v("f2"), "ascii", errors="ignore"))
- Result:
f1:test f2:test test data
- Raw log:
- Example 3
- Raw log:
f2: test test data
- Transformation rule:
e_set("f1", str_encode(v("f2"), "ascii", errors="strict"))
- Result:
An error is reported during execution.
- Raw log:
- Example 4
- Raw log:
f2: test test data
- Transformation rule:
e_set("f1", str_encode(v("f2"), "ascii", errors="replace"))
- Result:
f1:test ???? f2:test test data
- Raw log:
- Example 5
- Raw log:
f2: test test data
- Transformation rule:
e_set("f1", str_encode(v("f2"), "ascii", errors="xmlcharrefreplace"))
- Result:
f1:test 测试数据 f2:test test data
- Raw log:
- Example 1
str_decode
-
Syntax
str_decode(value, "utf8", errors="ignore")
Note The str_decode function can process only the data of the byte data type. -
Parameters
Parameter Type Required Description value Arbitrary (automatically converted to the string type) Yes The value that you want to decode. encoding Arbitrary (automatically converted to the string type) No The encoding format. Default value: utf8. ASCII is supported. errors Arbitrary (automatically converted to the string type) No The method that is used to process characters if some characters cannot be recognized based on the encoding format. Valid values: - ignore: No characters are decoded. This is the default value.
- strict: An error is reported and the data of the log is discarded.
- replace: The unrecognized characters are replaced with question marks (?).
- xmlcharrefreplace: The unrecognized characters are replaced with XML characters.
-
Response
A decoded value is returned.
-
Examples
- Raw log:
test: asewds
- Transformation rule:
e_set("encoding", str_decode(b'\xe4\xbd\xa0\xe5\xa5\xbd', "utf8", 'strict'))
- Result:
test: asewds encoding: hello
- Raw log:
str_replace
-
Syntax
str_replace(value, old, new, count)
Note You can call this function by passing basic variable parameters. For more information, see Function invoking. -
Parameters
Parameter Type Required Description value Arbitrary (automatically converted to the string type) Yes The value in which you want to replace a string. old Arbitrary (automatically converted to the string type) Yes The string that you want to replace. new Arbitrary (automatically converted to the string type) Yes The string that you want to use to replace the specified string. count Number No The number of replacements. If you do not configure this parameter, the specified string in all occurrences in the value is replaced. -
Response
A new string is returned.
-
Examples
Convert a dictionary to the JSON format.
- Raw log:
content: {'referer': '-', 'request': 'GET /phpMyAdmin', 'status': 404, 'data-1': {'aaa': 'Mozilla', 'bbb': 'asde'}, 'data-2': {'up_adde': '-', 'up_host': '-'}}
- Transformation rule:
e_set("content_json", str_replace(ct_str(v("content")),"'",'"'))
- Result:
content: {'referer': '-', 'request': 'GET /phpMyAdmin', 'status': 404, 'data-1': {'aaa': 'Mozilla', 'bbb': 'asde'}, 'data-2': {'up_adde': '-', 'up_host': '-'}} content_json: {"referer": "-", "request": "GET /phpMyAdmin", "status": 404, "data-1": {"aaa": "Mozilla", "bbb": "asde"}, "data-2": {"up_adde": "-", "up_host": "-"}}
- Raw log:
str_sort
-
Syntax
str_sort(value, reverse=False)
-
Parameters
Parameter Type Required Description value Arbitrary (automatically converted to the string type) Yes The string that you want to sort. reverse Bool No Default value: False. This value specifies that the string is sorted in ascending order. -
Response
A sorted string is returned.
-
Examples
- Example 1: Sort the value of the str field in alphabetical order.
- Raw log:
str: twish
- Transformation rule:
e_set("str_sort", str_sort(v("str")))
- Result:
str: twish str_sort: histw
- Raw log:
- Example 2: Sort the value of the str field in reverse alphabetical order at a granularity
of two-letter pairs.
- Raw log:
str: twish
- Transformation rule:
e_set("str_sort", str_sort(v("str"), reverse=True))
- Result:
str: twish str_sort: wtsih
- Raw log:
- Example 1: Sort the value of the str field in alphabetical order.
str_reverse
-
Syntax
str_reverse(value)
-
Parameters
Parameter Type Required Description value Arbitrary (automatically converted to the string type) Yes The value that you want to reverse. -
Response
A reversed string is returned.
-
Examples
Reverse the value of the data field.
- Raw log:
data:twish
- Transformation rule:
e_set("reverse_data", str_reverse(v("data")))
- Result:
data:twish reverse_data:hsiwt
- Raw log:
str_logstash_config_normalize
The function is used to convert data in the Logstash configuration language to the JSON format.
-
Syntax
str_logstash_config_normalize(value)
Note For more information about the Logstash configuration language, see Logstash. -
Parameters
Parameter Type Required Description value Arbitrary (automatically converted to the string type) Yes The value that you want to convert. -
Response
A converted string is returned.
-
Examples
Convert the value of the field in Logstash.
- Raw log:
logstash: {"name"=>"tw5"}
- Transformation rule:
e_set("normalize_data", str_logstash_config_normalize(v("logstash")))
- Result:
logstash: {"name"=>"tw5"} normalize_data:{"name":"tw5"}
- Raw log:
str_hex_escape_encode
The function is used to escape special characters. The function can escape hexadecimal characters to Chinese characters.
-
Syntax
str_hex_escape_encode(value)
-
Parameters
Parameter Type Required Description value Arbitrary (automatically converted to the string type) Yes The value that you want to escape. -
Response
An escaped string is returned.
-
Examples
Escape the value of the myfriend field to Chinese characters.
- Raw log:
myfriend: \xE6\x9F\xB3\xE4\xBA\x91
- Transformation rule:
e_set("hex_myfriend", str_hex_escape_encode("myfriend"))
- Result:
hex_myfriend:myfriend myfriend:\xE6\x9F\xB3\xE4\xBA\x91
- Raw log:
str_strip
The function is used to delete specified characters from a string.
-
Syntax
str_strip(value, chars)
-
Parameters
Parameter Type Required Description value Arbitrary (automatically converted to the string type) Yes The original string that you want to modify. chars Arbitrary (automatically converted to the string type) No The character set that you want to delete from the start and end of the specified string. Default value: \t\r\n
. -
Response
A modified string is returned.
-
Examples
- Example 1: Delete the asterisks (
*
) from the start of the value of the strip field.- Raw log:
strip: ***I love Etl
- Transformation rule:
e_set("str_strip", str_strip(v("strip"), "*"))
- Result:
strip: ***I love Etl str_strip:I love Etl
- Raw log:
- Example 2: Delete the spaces from the start of the value of the strip field.
- Raw log:
strip: I love Etl
- Transformation rule:
e_set("str_strip", str_strip(v("strip")))
- Result:
strip: I love Etl str_strip: I love Etl
- Raw log:
- Example 3: Delete the character set
xy
.- Raw log:
strip:xy123yx
- Transformation rule:
e_set("str_strip", str_strip(v("strip"), "xy"))
- Result:
strip:xy123yx str_strip:123
- Raw log:
- Example 1: Delete the asterisks (
str_lower
The function is used to convert all uppercase letters in a string to lowercase letters.
-
Syntax
str_lower(value)
-
Parameters
Parameter Type Required Description value Arbitrary (automatically converted to the string type) Yes The string that you want to convert. -
Response
A converted string is returned.
-
Examples
Convert the value of the name field to lowercase letters.
- Raw log:
name: Etl
- Transformation rule:
e_set("str_lower", str_lower(v("name")))
- Result:
name: Etl str_lower: etl
- Raw log:
str_upper
The function is used to convert all lowercase letters in a string to uppercase letters.
-
Syntax
str_upper(value)
-
Parameters
Parameter Type Required Description value Arbitrary (automatically converted to the string type) Yes The string that you want to convert. -
Response
A converted string is returned.
-
Examples
Convert the value of the name field to uppercase letters.
- Raw log:
name: etl
- Transformation rule:
e_set("str_upper", str_upper(v("name")))
- Result:
name: etl str_upper: ETL
- Raw log:
str_title
The function is used to capitalize the first letter of each word in a string and converts the other letters in the string to lowercase letters.
-
Syntax
str_title(value)
-
Parameters
Parameter Type Required Description value Arbitrary (automatically converted to the string type) Yes The string that you want to convert. -
Response
A converted string is returned.
-
Examples
Capitalize the first letter of each word in the value of the word field.- Raw log:
word: this is etl
- Transformation rule:
e_set("str_title", str_title(v("word")))
- Result:
word: this is etl str_title: This Is Etl
- Raw log:
str_capitalize
The function is used to capitalize the first letter of a string and converts the other letters in the string to lowercase letters.
-
Syntax
str_capitalize(value)
-
Parameters
Parameter Type Required Description value Arbitrary (automatically converted to the string type) Yes The string that you want to convert. -
Response
A converted string is returned.
-
Examples
Capitalize the first letter of the value of the word field and convert the other letters in the value to lowercase letters.- Raw log:
word: this Is MY EAL
- Transformation rule:
e_set("str_capitalize", str_capitalize(v("word")))
- Result:
word: this Is MY EAL str_capitalize: This is my eal
- Raw log:
str_lstrip
The function is used to delete specified characters from the start of a string.
-
Syntax
str_lstrip(value, chars)
-
Parameters
Parameter Type Required Description value Arbitrary (automatically converted to the string type) Yes The original string that you want to modify. chars Arbitrary (automatically converted to the string type) No The character set that you want to delete from the start of the string. Default value: space. -
Response
A modified string is returned.
-
Examples
- Example 1: Delete the asterisks (*) from the start of the value of the word field.
- Raw log:
word: ***this is string
- Transformation rule:
e_set("str_lstrip", str_lstrip(v("word"), "*"))
- Result:
word: ***this is string str_lstrip: this is string
- Raw log:
- Example 2: Delete the spaces from the start of the value of the word field.
- Raw log:
word: this is string
- Transformation rule:
e_set("str_lstrip", str_lstrip(v("word")))
- Result:
word: this is string str_lstrip: this is string
- Raw log:
- Example 3: Delete the character set
xy
.- Raw log:
lstrip:xy123yx
- Transformation rule:
e_set("str_lstrip", str_lstrip(v("lstrip"),"xy"))
- Result:
lstrip:xy123yx str_lstrip:123yx
- Raw log:
- Example 1: Delete the asterisks (*) from the start of the value of the word field.
str_rstrip
The function is used to delete specified characters from the end of a string.
-
Syntax
str_rstrip(value, chars)
-
Parameters
Parameter Type Required Description value Arbitrary (automatically converted to the string type) Yes The original string that you want to modify. chars Arbitrary (automatically converted to the string type) No The character set that you want to delete from the end of the string. Default value: space. -
Response
A modified string is returned.
-
Examples
- Example 1: Delete the asterisks (*) from the end of the value of the word field.
- Raw log:
word: this is string*****
- Transformation rule:
e_set("str_rstrip", str_rstrip(v("word"), "*"))
- Result:
word: this is string***** str_rstrip: this is string
- Raw log:
- Example 2: Delete the character set
xy
.- Raw log:
word:xy123yx
- Transformation rule:
e_set("str_rstrip", str_rstrip(v("word"), "xy"))
- Result:
word:xy123yx str_rstrip:xy123
- Raw log:
- Example 1: Delete the asterisks (*) from the end of the value of the word field.
str_swapcase
The function is used to convert the uppercase letters into lowercase letters and lowercase letters into uppercase letters in a string.
-
Syntax
str_swapcase(value)
-
Parameters
Parameter Type Required Description value Arbitrary (automatically converted to the string type) Yes The string that you want to convert. -
Response
A converted string is returned.
-
Examples
- Raw log:
name: this is string
- Transformation rule:
e_set("str_swapcase", str_swapcase(v("name")))
- Result:
name: this is string str_swapcase: THIS IS STRING
- Raw log:
str_translate
The function is used to replace specified characters in a string with mapping characters.
-
Syntax
str_translate(value, replace_string, mapping_string)
-
Parameters
Parameter Type Required Description value Arbitrary (automatically converted to the string type) Yes The original string in which you want to replace characters. replace_string Arbitrary (automatically converted to the string type) Yes The original character set whose characters you want to replace. mapping_string Arbitrary (automatically converted to the string type) Yes The character set that is used to replace characters in the original character set. -
Response
A processed string is returned.
-
Examples
- Raw log:
name: I love ETL!!!
- Transformation rule:
e_set("str_translate", str_translate(v("name"), "aeiou", "12345"))
- Result:
name: I love ETL!!! str_translate: I l4v2 ETL!!!
- Raw log:
str_endswith
The function is used to check whether a string ends with a specified suffix.
-
Syntax
str_endswith(value, suffix, start, end)
Note You can call this function by passing basic variable parameters. For more information, see Function invoking. -
Parameters
Parameter Type Required Description value Arbitrary (automatically converted to the string type) Yes The original string that you want to check. suffix Arbitrary (automatically converted to the string type) Yes The suffix. The value of this parameter can be a string or an element. start Number No The position from which the string prefix check starts. The value 0 specifies the first character. The value -1 specifies the last character.
end Number No The position at which the string prefix check ends. The value 0 specifies the first character. The value -1 specifies the last character.
-
Response
If the string ends with the specified suffix, the value True is returned. Otherwise, the value False is returned.
-
Examples
- Raw log:
name: this is endswith!!!
- Transformation rule:
e_set("str_endswith",str_endswith(v("name"), "!"))
- Result:
name: this is endswith!!! str_endswith: True
- Raw log:
str_startswith
The function is used to check whether a string starts with a specified string.
-
Syntax
str_startswith(value, prefix, start, end)
Note You can call this function by passing basic variable parameters. For more information, see Function invoking. -
Parameters
Parameter Type Required Description value Arbitrary (automatically converted to the string type) Yes The original string that you want to check. prefix Arbitrary (automatically converted to the string type) Yes The prefix. The value of this parameter can be a string or an element. start Number No The position from which the string prefix check starts. The value 0 specifies the first character. The value -1 specifies the last character.
end Number No The position at which the string prefix check ends. The value 0 specifies the first character. The value -1 specifies the last character.
-
Response
If the string starts with the specified prefix, the value True is returned. Otherwise, the value False is returned.
-
Examples
- Raw log:
name: !! this is startwith
- Transformation rule:
e_set("str_startswith",str_startswith(v("name"), "!!"))
- Result:
name: !! this is startwith str_startswith: True
- Raw log:
str_find
The function is used to check whether a string contains a specified substring.
-
Syntax
str_find(value, str, begin, end)
Note You can call this function by passing basic variable parameters. For more information, see Function invoking. -
Parameters
Parameter Type Required Description value Arbitrary (automatically converted to the string type) Yes The original string in which you want to search for a substring. str Arbitrary (automatically converted to the string type) Yes The substring that you want to search for. begin Number No The position from which the substring search starts. The default value 0 specifies the first character. The value -1 specifies the last character.
end Number No The position at which the substring search ends. The default value is the length of the string. The value 0 specifies the first character. The value -1 specifies the last character.
-
Response
The position of the specified substring in the original string is returned. If the specified substring appears multiple times in the original string, only the position of the first occurrence of the substring is returned.
-
Examples
- Raw log:
name: hello world
- Transformation rule:
e_set("str_find",str_find(v("name"), "h"))
- Result:
name: hello world str_find: 0
- Raw log:
str_count
The function is used to count the number of occurrences of a character in a string.
-
Syntax
str_count(value, sub, start, end)
Note You can call this function by passing basic variable parameters. For more information, see Function invoking. -
Parameters
Parameter Type Required Description value Arbitrary (automatically converted to the string type) Yes The original string in which you want to count the number of occurrences of a character. sub Arbitrary (automatically converted to the string type) Yes The character whose number of occurrences you want to count. start Number No The position from which the search for the specified character starts in the string. Valid values: - 0: the first character. This is the default value.
- -1: the last character.
end Number No The position at which the search for the specified character ends in the string. Valid values: - 0: the first character.
- -1: the last character. This is the default value.
-
Response
The number of occurrences of the specified character is returned.
-
Examples
- Raw log:
name: this is really a string
- Transformation rule:
e_set("str_count", str_count(v("name"), "i"))
- Result:
name: this is really a string str_count: 3
- Raw log:
str_rfind
The function is used to return the position of the last occurrence of a specified string or a specified character in a string.
-
Syntax
str_rfind(value, substr, beg, end)
Note You can call this function by passing basic variable parameters. For more information, see Function invoking. -
Parameters
Parameter Type Required Description value Arbitrary (automatically converted to the string type) Yes The original string in which you want to search for a character. substr Arbitrary (automatically converted to the string type) Yes The character that you want to search for. beg Number No The position from which the search starts. Default value: 0. end Number No The position at which the search ends. The default value is the length of the string. -
Response
The position of the last occurrence of the specified character or string is returned.
-
Examples
- Raw log:
name: this is really a string
- Transformation rule:
e_set("str_rfind", str_rfind(v("name"), "i"))
- Result:
name: this is really a string str_rfind: 20
- Raw log:
str_split
The function is used to split a string by using a specified delimiter.
-
Syntax
str_split(value, sep=None, maxsplit=-1)
-
Parameters
Parameter Type Required Description value Arbitrary (automatically converted to the string type) Yes The original string that you want to split. sep Number No The delimiter. The value None specifies a space. maxsplit Number No The maximum number of strings into which you can split the original string. The value -1 specifies no limit. -
Response
A processed string is returned.
-
Examples
Split the value of the content field by using the space delimiter.- Raw log:
content: hello world
- Transformation rule:
e_set("str_split", str_split(v("content"), " "))
- Result:
content: hello world str_split: ["hello", "world"]
- Raw log:
str_splitlines
The function is used to split a string by using a line feed.
-
Syntax
str_splitlines(value, keepends)
-
Parameters
Parameter Type Required Description value Arbitrary (automatically converted to the string type) Yes The original string that you want to split. keepends Bool No Specifies whether to delete line feeds from the output result. The line feeds include \r
,\r\n
, and\n
. Default value: False. This value specifies that line feeds are deleted. The value True specifies that line feeds are retained. -
Response
Processed strings are returned.
-
Examples
- Example 1
- Raw log:
content: ab c\n\nde fg\rkl\r\n
- Transformation rule:
e_set("str_splitlines", str_splitlines(v("content"), False))
- Result:
content: ab c\n\nde fg\rkl\r\n str_splitlines: ['ab c', '', 'de fg', 'kl']
- Raw log:
- Example 2
- Raw log:
content: ab c\n\nde fg\rkl\r\n
- Transformation rule:
e_set("str_splitlines", str_splitlines(v("content"), True))
- Result:
content: ab c\n\nde fg\rkl\r\n str_splitlines: ['ab c\n', '\n', 'de fg\r', 'kl\r\n']
- Raw log:
- Example 1
str_partition
The function is used to split a string into three parts from left to right by using a specified delimiter.
-
Syntax
str_partition(value, substr)
-
Parameters
Parameter Type Required Description value Arbitrary (automatically converted to the string type) Yes The string that you want to split. substr Arbitrary (automatically converted to the string type) No The specified delimiter. -
Response
Split strings are returned.
-
Examples
Split the value of the website field into three parts from left to right by using the.
delimiter.- Raw log:
website: www.aliyun.com
- Transformation rule:
e_set("str_partition", str_partition(v("website"), "."))
- Result:
website: www.aliyun.com str_partition: ["www", ".", "aliyun.com"]
- Raw log:
str_rpartition
The function is used to split a string into three parts from right to left by using a specified delimiter.
-
Syntax
str_rpartition(value, substr)
-
Parameters
Parameter Type Required Description value Arbitrary (automatically converted to the string type) Yes The original string that you want to split. substr Arbitrary (automatically converted to the string type) No The specified delimiter. -
Response
Processed strings are returned.
-
Examples
Split the value of the website field into three parts from right to left by using the.
delimiter.- Raw log:
website: www.aliyun.com
- Transformation rule:
e_set("str_partition", str_rpartition(v("website"), "."))
- Result:
website: www.aliyun.com str_partition: ["www.aliyun", ".", "com"]
- Raw log:
str_center
The function is used to pad a string to a specified length by using a specified character.
-
Syntax
str_center(value, width, fillchar)
-
Parameters
Parameter Type Required Description value Arbitrary (automatically converted to the string type) Yes The original string that you want to modify. width Number Yes The length of the string after padding. fillchar Arbitrary (automatically converted to the string type) No The character that is used for padding. Default value: space. -
Response
A processed string is returned.Note If the length of the string after padding is less than the length of the original string, the original string is returned. -
Examples
- Example 1: Pad a string by using asterisks (
*
).- Raw log:
center: this is center
- Transformation rule:
e_set("str_center", str_center(v("center"), 40, "*"))
- Result:
center: this is center str_center: *************this is center*************
- Raw log:
- Example 2: Pad a string by using spaces.
- Raw log:
center: this is center
- Transformation rule:
e_set("str_center", str_center(v("center"), 40))
- Result:
center: this is center str_center: this is center
- Raw log:
- Example 1: Pad a string by using asterisks (
str_zfill
The function is used to pad a string to a specified length by using 0 from the start of the string.
-
Syntax
str_zfill(value, width)
-
Parameters
Parameter Type Required Description value Arbitrary (automatically converted to the string type) Yes The original string that you want to modify. width Number Yes The length of the string after padding. -
Response
A processed string is returned.
-
Examples
- Raw log:
center: this is zfill
- Transformation rule:
e_set("str_zfill", str_zfill(v("center"), 40))
- Result:
center:this is zfill str_zfill:000000000000000000000000000this is zfill
- Raw log:
str_expandtabs
The function is used to convert \t
in a string to spaces.
-
Syntax
str_expandtabs(value, tabsize)
-
Parameters
Parameter Type Required Description value Arbitrary (automatically converted to the string type) Yes The original string that you want to modify. tabsize Number Yes The number of spaces after conversion. -
Response
A processed string is returned.
-
Examples
- Example 1: Convert
\t
in the value of the field in Logstash to a space.- Raw log:
logstash: this is\tstring
- Transformation rule:
e_set("str_expandtabs", str_expandtabs(v("logstash")))
- Result:
logstash: this is\tstring str_expandtabs: this is string
- Raw log:
- Example 2: Convert
\t
in the value of the center field to spaces.- Raw log:
{"center": "this is\tstring"}
- Transformation rule:
e_set("str_expandtabs", str_expandtabs(v("center"), 16))
- Result:
center: this is\tstring str_expandtabs: this is string
- Raw log:
- Example 1: Convert
str_ljust
The function is used to pad a string to a specified length by using a specified character from the end of the string.
-
Syntax
str_ljust(value, width, fillchar)
-
Parameters
Parameter Type Required Description value Arbitrary (automatically converted to the string type) Yes The original string that you want to modify. width Number Yes The length of the string after padding. fillchar Arbitrary (automatically converted to the string type) No The character that is used for padding. Default value: space. -
Response
A processed string is returned.Note If the length of the string after padding is less than the length of the original string, the original string is returned. -
Examples
- Example 1
- Raw log:
content: this is ljust
- Transformation rule:
e_set("str_ljust", str_ljust(v("content"), 20, "*"))
- Result:
content: this is ljust str_ljust: this is ljust*******
- Raw log:
- Example 2
- Raw log:
center: this is ljust
- Transformation rule:
e_set("str_ljust", str_ljust(v("center"), 20,))
- Result:
center: this is ljust str_ljust: this is ljust
- Raw log:
- Example 3: The value of width is less than the length of the original string. The
original string is returned.
- Raw log:
center: this is ljust
- Transformation rule:
e_set("str_ljust", str_ljust(v("center"),10, "*"))
- Result:
center: this is ljust str_ljust: this is ljust
- Raw log:
- Example 1
str_rjust
The function is used to pad a string to a specified length by using a specified character from the start of the string.
-
Syntax
str_rjust(value, width, fillchar)
-
Parameters
Parameter Type Required Description value Arbitrary (automatically converted to the string type) Yes The original string that you want to modify. width Number Yes The length of the string after padding. fillchar Arbitrary (automatically converted to the string type) No The character that is used for padding. Default value: space. -
Response
A processed string is returned.Note If the length of the string after padding is less than the length of the original string, the original string is returned. -
Examples
- Raw log:
center: this is rjust
- Transformation rule:
e_set("str_rjust", str_rjust(v("center"), 20, "*"))
- Result:
center: this is rjust str_rjust: *******this is rjust
- Raw log:
str_zip
The function is used to concurrently split two values or strings that are returned by expressions and combines the results into one string.
-
Syntax
str_zip(value1, value2, combine_sep=None, sep=None, quote=None, lparse=None, rparse=None)
-
Parameters
Parameter Type Required Description value1 Arbitrary (automatically converted to the string type) Yes The value that you want to combine. value2 Arbitrary (automatically converted to the string type) Yes The value that you want to combine. combine_sep Arbitrary (automatically converted to the string type) No The identifier that is used when elements are combined. Default value: #
.sep Arbitrary (automatically converted to the string type) No The delimiter that is used between the elements after the combination. The value must be a single character. Default value: ,
.quote Arbitrary (automatically converted to the string type) No The character is used to enclose the elements after the combination. This parameter is required if the values contain delimiters. Default value: "
.lparse Arbitrary (automatically converted to the string type) No The delimiter and quote that are used among the elements of value 1
. Default delimiter:,
. Default quote:"
. Format:lparse=(',', '"')
.Note The quote has a higher priority than the delimiter.rparse Arbitrary (automatically converted to the string type) No The delimiter and quote that are used among the elements of value 2
. Default delimiter,
. Default quote:"
. Format:rparse=(',', '"')
.Note The quote has a higher priority than the delimiter. -
Response
A combined string is returned.
-
Examples
- Example 1
- Raw log:
website: wwww.aliyun.com escape_name: o
- Transformation rule:
e_set("combine", str_zip(v("website"), v("escape_name"), combine_sep="@"))
- Result:
website: wwww.aliyun.com escape_name: o combine: wwww.aliyun.com@o
- Raw log:
- Example 2
- Raw log:
website: wwww.aliyun.com escape_name: o
- Transformation rule:
e_set("combine", str_zip(v("website"), v("escape_name")))
- Result:
combine:wwww.aliyun.com@o escape_name:o website:wwww.aliyun.com
- Raw log:
- Example 3: In this example, the sep parameter is used.
- Raw log:
f1: a,b,c f2: x,y,z
- Transformation rule:
e_set("combine", str_zip(v("f1"), v("f2"), sep="|"))
- Result:
f1: a,b,c f2: x,y,z combine: a#x|b#y|c#z
- Raw log:
- Example 4: In this example, the quote parameter is used.
- Raw log:
f1: "a,a", b, "c,c" f2: x, "y,y", z
- Transformation rule:
e_set("combine", str_zip(v("f1"), v("f2"), quote='|'))
- Result:
f1: "a,a", b, "c,c" f2: x, "y,y", z combine: |a,a#x|,|b#y,y|,|c,c#z|
- Raw log:
- Example 5: In this example, field values with different lengths are used.
- Raw log:
f1: a,b f2: x,y,z
- Transformation rule:
e_set("combine", str_zip(v("f1"), v("f2")))
- Result:
f1: a,b f2: x,y,z combine: a#x,b#y
- Raw log:
- Example 6: In this example, the lparse and rparse parameters are used.
- Raw log:
f1: a#b#c f2: x|y|z
- Transformation rule:
e_set("combine", str_zip(v("f1"), v("f2"), lparse=("#", '"'), rparse=("|", '"')))
- Result:
f1: a#b#c f2: x|y|z combine: a#x,b#y,c#z
- Raw log:
- Example 7: In this example, the lparse and rparse parameters are used.
- Raw log:
f1: |a,a|, b, |c,c| f2: x, #y,y#, z
- Transformation rule:
e_set("combine", str_zip(v("f1"), v("f2"), lparse=(",", '|'), rparse=(",", '#')))
- Result:
f1: |a,a|, b, |c,c| f2: x, #y,y#, z combine: "a,a#x","b#y,y","c,c#z"
- Raw log:
- Example 1
str_isalnum
The function is used to check whether a string contains only letters and digits.
-
Syntax
str_isalnum(value)
-
Parameters
Parameter Type Required Description value Arbitrary (automatically converted to the string type) Yes The string that you want to check. -
Response
The value True or False is returned.
-
Examples
- Raw log:
content: 13
- Transformation rule:
e_set("str_isalnum", str_isalnum(v("content")))
- Result:
content: 13 str_isalnum: True
- Raw log:
str_isalpha
The function is used to check whether a string contains only letters.
-
Syntax
str_isalpha(value)
-
Parameters
Parameter Type Required Description value Arbitrary (automatically converted to the string type) Yes The string that you want to check. -
Response
The value True or False is returned.
-
Examples
- Raw log:
content: 13
- Transformation rule:
e_set("str_isalpha", str_isalpha(v("content")))
- Result:
content: 13 str_isalpha: False
- Raw log:
str_isascii
The function is used to check whether a string is in the ASCII table.
-
Syntax
str_isascii(value)
-
Parameters
Parameter Type Required Description value Arbitrary (automatically converted to the string type) Yes The string that you want to check. -
Response
The value True or False is returned.
-
Examples
- Raw log:
content: asw123
- Transformation rule:
e_set("str_isascii", str_isascii(v("content")))
- Result:
content: asw123 str_isascii: True
- Raw log:
str_isdecimal
The function is used to check whether a string contains only decimal characters.
-
Syntax
str_isdecimal(value)
-
Parameters
Parameter Type Required Description value Arbitrary (automatically converted to the string type) Yes The string that you want to check. -
Response
The value True or False is returned.
-
Examples
- Example 1
- Raw log:
welcome: hello
- Transformation rule:
e_set("str_isdecimal", str_isdecimal(v("welcome")))
- Result:
welcome: hello str_isdecimal: False
- Raw log:
- Example 2
- Raw log:
num: 123
- Transformation rule:
e_set("str_isdecimal", str_isdecimal(v("num")))
- Result:
num: 123 str_isdecimal: True
- Raw log:
- Example 1
str_isdigit
The function is used to check whether a string contains only digits.
-
Syntax
str_isdigit(value)
-
Parameters
Parameter Type Required Description value Arbitrary (automatically converted to the string type) Yes The string that you want to check. -
Response
The value True or False is returned.
-
Examples
- Raw log:
content: 13
- Transformation rule:
e_set("str_isdigit", str_isdigit(v("content")))
- Result:
content: 13 str_isdigit: True
- Raw log:
str_isidentifier
The function is used to check whether a string is a valid Python identifier or checks whether a variable name is valid.
-
Syntax
str_isidentifier(value)
-
Parameters
Parameter Type Required Description value Arbitrary (automatically converted to the string type) Yes The string that you want to check. -
Response
The value True or False is returned.
-
Examples
- Raw log:
class: class
- Transformation rule:
e_set("str_isidentifier", str_isidentifier(v("class")))
- Result:
class: class str_isidentifier: True
- Raw log:
str_islower
The function is used to check whether a string contains lowercase letters.
-
Syntax
str_islower(value)
-
Parameters
Parameter Type Required Description value Arbitrary (automatically converted to the string type) Yes The string that you want to check. -
Response
The value True or False is returned.
-
Examples
- Raw log:
lower: asds
- Transformation rule:
e_set("str_islower", str_islower(v("lower")))
- Result:
lower: asds str_islower: True
- Raw log:
str_isnumeric
The function is used to check whether a string contains digits.
-
Syntax
str_isnumeric(value)
-
Parameters
Parameter Type Required Description value Arbitrary (automatically converted to the string type) Yes The string that you want to check. -
Response
The value True or False is returned.
-
Examples
- Raw log:
num: 123
- Transformation rule:
e_set("str_isnumeric", str_isnumeric(v("num")))
- Result:
num: 123 str_isnumeric: True
- Raw log:
str_isprintable
The function is used to check whether all characters in a string are printable characters.
-
Syntax
str_isprintable(value)
-
Parameters
Parameter Type Required Description value Arbitrary (automatically converted to the string type) Yes The string that you want to check. -
Response
The value True or False is returned.
-
Examples
- Raw log:
content: vs;,.as
- Transformation rule:
e_set("str_isprintable", str_isprintable(v("content")))
- Result:
content: vs;,.as str_isprintable: True
- Raw log:
str_isspace
The function is used to check whether a string contains only spaces.
-
Syntax
str_isspace(value)
-
Parameters
Parameter Type Required Description value Arbitrary (automatically converted to the string type) Yes The string that you want to check. -
Response
The value True or False is returned.
-
Examples
- Raw log:
space: as afsd
- Transformation rule:
e_set("str_isspace", str_isspace(v("space")))
- Result:
space: as afsd str_isspace: False
- Raw log:
str_istitle
The function is used to check whether the first letter of each word in a string is in upper case and the other letters in the string are in lower case.
-
Syntax
str_istitle(value)
-
Parameters
Parameter Type Required Description value Arbitrary (automatically converted to the string type) Yes The string that you want to check. -
Response
The value True or False is returned.
-
Examples
- Raw log:
title: Alex Is A Boy
- Transformation rule:
e_set("str_istitle", str_istitle(v("title")))
- Result:
str_istitle:true title:Alex Is A Boy
- Raw log:
str_isupper
The function is used to check whether all letters in a string are in upper case.
-
Syntax
str_isupper(value)
-
Parameters
Parameter Type Required Description value Arbitrary (automatically converted to the string type) Yes The string that you want to check. -
Response
The value True or False is returned.
-
Examples
- Raw log:
content: ASSD
- Transformation rule:
e_set("str_isupper", str_isupper(v("content")))
- Result:
content: ASSD str_isupper: True
- Raw log:
str_uuid
-
Syntax
str_uuid(lower=True)
-
Parameters
Parameter Type Required Description lower Bool No Specifies whether the letters in the output UUID are in lower case. Default value: True. This value specifies that the letters are in lower case. -
Response
A UUID is returned.
-
Examples
- Example 1
- Raw log:
content: I am Iron man
- Transformation rule:
e_set("UUID", str_uuid())
- Result:
content: I am Iron man UUID: e9fcd6b0-b970-11ec-979d-0f7041e65ab8
- Raw log:
- Example 2
- Raw log:
content: I am Iron man
- Transformation rule:
e_set("UUID", str_uuid(lower=False))
- Result:
content: I am Iron man UUID: 0649211E-B971-11EC-A258-E71F0A2930C5
- Raw log:
- Example 1