本文主要介绍字符串函数的语法规则,包括参数解释、函数示例等。
函数列表
类型 | 函数 | 说明 |
---|---|---|
多字符串操作 | str_format | 将字符串进行格式化。 |
str_join | 通过连接符将输入的字符串连接生成一个新的字符串。 | |
str_zip | 将两个值或表达式的字符串进行并发分裂然后再合并成一个字符串。 | |
编码解码 | str_encode | 按照指定的编码格式对字符串进行编码。 |
str_decode | 按照指定的编码格式对传入值进行解码。 | |
str_hex_escape_encode | 将特殊字符进行转义,支持十六进制字符转义为中文字符。 | |
str_uuid | 随机生成UUID。 | |
排序、倒叙、替换 | str_sort | 将指定的对象进行排序。 |
str_reverse | 将一个字符串进行反转。 | |
str_replace | 将旧字符串根据规则替换成新字符串。 | |
str_logstash_config_normalize | 将Logstash配置语言转成JSON格式。 | |
str_translate | 将字符串中的指定字符按照对应关系进行替换。 | |
常规规整 | str_strip | 删除字符串中指定的字符。 |
str_lstrip | 删除字符串开头的指定字符。 | |
str_rstrip | 删除字符串结尾的指定字符。 | |
str_lower | 将字符串中所有大写字符转换为小写字符。 | |
str_upper | 将字符串中所有小写字符转换为大写字符。 | |
str_title | 将所有单词的第一个字母转化为大写,其余字母均为小写。 | |
str_capitalize | 将字符串的第一个字母转化为大写,其他字母转化为小写。 | |
str_swapcase | 对字符串的大小写字母进行转换。 | |
查找判断 | str_count | 统计字符串里某个字符出现的次数。 |
str_find | 判断原字符串中是否包含指定的子字符串。 | |
str_rfind | 查找字符串中指定字符或者字符串最后一次出现的位置。 | |
str_endswith | 判断字符串是否以指定后缀结尾。 | |
str_startswith | 判断字符串是否以指定字符串开头。 | |
切分 | str_split | 通过指定分隔符对字符串进行分割。 |
str_splitlines | 通过换行符符对字符串进行分割。 | |
str_partition | 根据指定的分隔符将字符串从左往右分割为三部分。 | |
str_rpartition | 根据指定的分隔符将字符串从右往左分割为三部分。 | |
格式化 | str_center | 用指定字符将字符串填充到指定长度。 |
str_ljust | 用指定字符将字符串从结尾填充至指定长度。 | |
str_rjust | 用指定字符将原字符串从开头填充至指定长度。 | |
str_zfill | 用字符0从开头将字符串填充至指定长度。 | |
str_expandtabs | 将字符串中的\t 转为空格。
|
|
字符集判断 | str_isalnum | 判断字符串是仅由字母和数字组成。 |
str_isalpha | 判断字符串是否仅由字母组成。 | |
str_isascii | 判断字符串是否在ASCII中。 | |
str_isdecimal | 判断字符串是否仅包含十进制字符。 | |
str_isdigit | 判断字符串是否仅由数字组成。 | |
str_isidentifier | 判断字符串是否是有效的Python标识符,也可以用来判断变量名是否合法。 | |
str_islower | 判断字符串是否由小写字母组成。 | |
str_isnumeric | 判断字符串是否由数字组成。 | |
str_isprintable | 判断字符串中是否所有字符都是可打印字符。 | |
str_isspace | 判断字符串是否仅由空格字符组成。 | |
str_istitle | 判断字符串中所有单词的拼写首字母是否为大写,且其他字母为小写。 | |
str_isupper | 字符串中所有的字母是否都为大写。 |
str_format
- 函数格式
str_format(格式化字符串, 值1,值2, ...)
- 参数说明
参数名称 参数类型 是否必填 说明 格式化字符串 任意(自动转为String) 是 转换后的格式。例如 {}={}
。值1 任意 是 待格式化的值1。 值2 任意 是 待格式化的值2。 - 返回结果
返回格式化后的字符串。
- 函数示例
原始日志:
class: Format escape_name: Traditional
加工规则:e_set("str_format", str_format("{}={}",v("class"),v("escape_name")))
加工结果:class: Format escape_name: Traditional str_format: Format=Traditional
str_join
- 函数格式
str_join(连接符,值1, 值2, ....)
- 参数说明
参数名称 参数类型 是否必填 说明 连接符 任意(自动转为String) 是 连接符。例如感叹号(!)、at符号(@)、井号(#)、美元符号($)、百分号(%)等。 值1 任意(自动转为String) 是 待连接的值。 值2 任意(自动转为String) 是 待连接的值。 - 返回结果
返回连接后的字符串。
- 函数示例
原始日志:
name: ETL company: aliyun.com
加工规则:e_set("email", str_join("@",v("name"),v("company")))
加工结果:name: ETL company: aliyun.com email:ETL@aliyun.com
str_encode
- 函数格式
str_encode(值, "utf8", errors="ignore"))
- 参数说明
参数名称 参数类型 是否必填 说明 值 任意(自动转为String) 是 需要被编码的值。 encoding String 否 编码格式,默认为utf8。支持ASCII。 errors String 否 按照编码格式无法识别字符时的处理方式。取值包括: - ignore(默认值):忽略不做编解码。
- strict:直接报错,丢弃此条日志数据。
- replace:使用半角问号(?)替换无法识别部分。
- xmlcharrefreplace:使用对应XML字符替换无法识别部分。
- 返回结果
返回编码后的字符串。
- 函数示例
- 示例1
原始日志:
test: asewds
加工规则:e_set("f1", str_decode(str_encode("你好", "utf8"), "utf8"))
加工结果:test: asewds f1: 你好
- 示例2
原始日志:
f2: test 测试数据
加工规则:e_set("f1", str_encode(v("f2"), "ascii", errors="ignore"))
加工结果:f1:test f2:test 测试数据
- 示例3
原始日志:
f2: test 测试数据
加工规则:e_set("f1", str_encode(v("f2"), "ascii", errors="strict"))
加工结果:执行时直接报错。
- 示例4
原始日志:
f2: test 测试数据
加工规则:e_set("f1", str_encode(v("f2"), "ascii", errors="replace"))
加工结果:f1:test ???? f2:test 测试数据
- 示例5
原始日志:
f2: test 测试数据
加工规则:e_set("f1", str_encode(v("f2"), "ascii", errors="xmlcharrefreplace"))
加工结果:f1:test 测试数据 f2:test 测试数据
- 示例1
str_decode
- 函数格式
str_decode(值, "utf8", errors="ignore"))
说明 str_decode只能处理Byte类型的数据。 - 参数说明
参数名称 参数类型 是否必填 说明 值 任意(自动转为String) 是 需要被解码的值。 encoding 任意(自动转为String) 否 编码格式,默认为utf8。 支持ASCII。 errors 任意(自动转为String) 否 按照编码格式无法识别字符时的处理方式。取值包括: - ignore(默认值):忽略不做编解码。
- strict:直接报错,丢弃此条日志数据。
- replace:使用半角问号(?)替换无法编解码部分。
- xmlcharrefreplace:使用对应XML字符替换无法编解码部分。
- 返回结果
返回解码后的值。
- 函数示例
原始日志:
test: asewds
加工规则:e_set("encoding", str_decode(b'\xe4\xbd\xa0\xe5\xa5\xbd', "utf8",'strict'))
加工结果:test: asewds encoding: 你好
str_replace
- 函数格式
str_replace(值, old, new, count)
说明 该函数为基本变参调用形式,请参见函数调用方式。 - 参数说明
参数名称 参数类型 是否必填 说明 值 任意(自动转为String) 是 需要被替换的值。 old 任意(自动转为String) 是 需要被替换的字符串。 new 任意(自动转为String) 是 替换后新的字符串。 count Number 否 替换次数,可选项。如果不设置count,则表示替换所有。 - 返回结果
返回一个新字符串。
- 函数示例:将dict类型转成JSON类型。
原始日志:
content: {'referer': '-', 'request': 'GET /phpMyAdmin', 'status': 404, 'data-1': {'aaa': 'Mozilla', 'bbb': 'asde'}, 'data-2': {'up_adde': '-', 'up_host': '-'}}
加工规则:e_set("content_json", str_replace(ct_str(v("content")),"'",'"'))
加工结果: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": "-"}}
str_sort
- 函数格式
str_sort(值, reverse)
- 参数说明
参数名称 参数类型 是否必填 说明 值 任意(自动转为String) 是 需要被排序的原字符串。 reverse Bool 否 默认为False,表示升序排列。 - 返回结果
返回排序后的字符串。
- 函数示例
- 示例1:对str字符串整体进行排序。
原始日志:
str: twish
加工规则:e_set("str_sort", str_sort(v("str")))
加工结果:str: twish str_sort: histw
- 示例2:对str字符串进行两个一组的倒排序。
原始日志:
str: twish
加工规则:e_set("str_sort", str_sort(v("str"),True))
加工结果:str: twish str_sort: wtsih
- 示例1:对str字符串整体进行排序。
str_reverse
- 函数格式
str_reverse(值)
- 参数说明
参数名称 参数类型 是否必填 说明 值 任意(自动转为String) 是 需要被反转的值。 - 返回结果
返回反转后的字符串。
- 函数示例:对data进行反转。
原始日志:
data:twish
加工规则:e_set("reverse_data", str_reverse(v("data")))
加工结果:data:twish reverse_data:hsiwt
str_logstash_config_normalize
- 函数格式
str_logstash_config_normalize(值)
说明 关于Logstash类型说明请参见Logstash。 - 参数说明
参数名称 参数类型 是否必填 说明 值 任意(自动转为String) 是 需要被转换的值。 - 返回结果
返回转换后的字符串。
- 函数示例:对Logstash类型数据进行转换。
原始日志:
logstash: {"name"=>"tw5"}
加工规则:e_set("normalize_data", str_logstash_config_normalize(v("logstash")))
加工结果:logstash: {"name"=>"tw5"} normalize_data:{"name":"tw5"}
str_hex_escape_encode
- 函数格式
str_hex_escape_encode(值)
- 参数说明
参数名称 参数类型 是否必填 说明 值 任意(自动转为String) 是 需要被转义的值。 - 返回结果
返回转义后的字符串。
- 函数示例:对myfriend值转义为中文字符。
原始日志:
myfriend: \xe4\xbd\xa0\xe5\xa5\xbd
加工规则:e_set("hex_myfriend", str_hex_escape_encode(v("myfriend")))
加工结果:myfriend: \xe4\xbd\xa0\xe5\xa5\xbd hex_myfriend: 你好
str_strip
- 函数格式
str_strip(值, chars )
- 参数说明
参数名称 参数类型 是否必填 说明 值 任意(自动转为String) 是 需要被修改的原字符串。 chars 任意(自动转为String) 否 字符串开头和结尾需要删除的字符集,默认为 \t\r\n
。 - 返回结果
返回修改后的字符串。
- 函数示例
- 示例1:删除strip开头的*字符。
原始日志
strip: ***I love Etl
加工规则e_set("str_strip", str_strip(v("strip"),"*"))
加工结果strip: ***I love Etl str_strip:I love Etl
- 示例2:删除strip开头的空格。
原始日志
strip: I love Etl
加工规则e_set("str_strip", str_strip(v("strip")))
加工结果strip: I love Etl str_strip: I love Etl
- 示例3:删除的字符集为
xy
。原始日志strip:xy123yx
加工规则e_set("str_strip", str_strip(v("strip"),"xy"))
加工结果strip:xy123yx str_strip:123
- 示例1:删除strip开头的*字符。
str_lower
- 函数格式
str_lower(值)
- 参数说明
参数名称 参数类型 是否必填 说明 值 任意(自动转为String) 是 需要被转换的字符串。 - 返回结果
返回转换后的字符串。
- 函数示例:把name值全部转换成小写字母。
原始日志:
name: Etl
加工规则:e_set("str_lower", str_lower(v("name")))
加工结果:name: Etl str_lower: etl
str_upper
- 函数格式
str_upper(值)
- 参数说明
参数名称 参数类型 是否必填 说明 值 任意(自动转为String) 是 需要被转换的字符串。 - 返回结果
返回转换后的字符串。
- 函数示例:把name值全部转换成大写字母。
原始日志:
name: etl
加工规则:e_set("str_upper", str_upper(v("name")))
加工结果:name: etl str_upper: ETL
str_title
- 函数格式
str_title(值)
- 参数说明
参数名称 参数类型 是否必填 说明 值 任意(自动转为String) 是 需要被转换的字符串。 - 返回结果
返回转换后的字符串。
- 函数示例:将word字段值中所有单词的首字母转成大写。
原始日志:
word: this is etl
加工规则:e_set("str_title", str_title(v("word")))
加工结果:word: this is etl str_title: This Is Etl
str_capitalize
- 函数格式
str_capitalize(值)
- 参数说明
参数名称 参数类型 是否必填 说明 值 任意(自动转为String) 是 需要被转换的字符串。 - 返回结果
返回转换后的字符串。
- 函数示例:将word字段值中第一个字符转换为大写,其他字符转换为小写。
原始日志:
word: this Is MY EAL
加工规则:e_set("str_capitalize", str_capitalize(v("word")))
加工结果:word: this Is MY EAL str_capitalize: This is my eal
str_lstrip
- 函数格式
str_lstrip(值, chars)
- 参数说明
参数名称 参数类型 是否必填 说明 值 任意(自动转为String) 是 需要被修改的原字符串。 chars 任意(自动转为String) 否 字符串开头需要删除的字符集,默认为空格。 - 返回结果
返回修改后的字符串。
- 函数示例
- 示例1:去掉word字段开头的星号(*)。
原始日志:
word: ***this is string
加工规则:e_set("str_lstrip", str_lstrip(v("word"),"*"))
加工结果:word: ***this is string str_lstrip: this is string
- 示例2:删除word字段开头的空格。
原始日志:
word: this is string
加工规则:e_set("str_lstrip", str_lstrip(v("word")))
加工结果:word: this is string str_lstrip: this is string
- 示例3:删除字符集
xy
。原始日志:lstrip:xy123yx
加工规则:e_set("str_lstrip", str_lstrip(v("lstrip"),"xy"))
加工结果:lstrip:xy123yx str_lstrip:123yx
- 示例1:去掉word字段开头的星号(*)。
str_rstrip
- 函数格式
str_rstrip(值, chars)
- 参数说明
参数名称 参数类型 是否必填 说明 值 任意(自动转为String) 是 需要被修改的原字符串。 chars 任意(自动转为String) 否 字符串结尾需要删除的字符集,默认为空格。 - 返回结果
返回修改后的字符串。
- 函数示例
- 示例1:去掉word字段结尾的星号(*)。
原始日志:
word: this is string*****
加工规则:e_set("str_rstrip", str_rstrip(v("word"),"*"))
加工结果:word: this is string***** str_rstrip: this is string
- 示例2:删除字符集
xy
。原始日志:word:xy123yx
加工规则:e_set("str_rstrip", str_rstrip(v("word"),"xy"))
加工结果:word:xy123yx str_rstrip:xy123
- 示例1:去掉word字段结尾的星号(*)。
str_swapcase
- 函数格式
str_swapcase(值)
- 参数说明
参数名称 参数类型 是否必填 说明 值 任意(自动转为String) 是 需要被转换的字符串。 - 返回结果
返回转换后的字符串。
- 函数示例
原始日志:
name: this is string
加工规则:e_set("str_swapcase", str_swapcase(v("name")))
加工结果:name: this is string str_swapcase: THIS IS STRING
str_translate
- 函数格式
str_translate(值, 原字符集, 映射字符集)
- 参数说明
参数名称 参数类型 是否必填 说明 值 任意(自动转为String) 是 需要被替换的原字符串。 原字符集 任意(自动转为String) 是 原字符集合。 映射字符集 任意(自动转为String) 是 替换后的字符集合。 - 返回结果
返回处理后的字符串。
- 函数示例
原始日志:
name: I love ETL!!!
加工规则:e_set("str_translate", str_translate(v("name"),"aeiou","12345"))
加工结果:name: I love ETL!!! str_translate: I l4v2 ETL!!!
str_endswith
- 函数格式
str_endswith(值, suffix, start, end )
说明 该函数为基本变参调用形式,请参见函数调用方式。 - 参数说明
参数名称 参数类型 是否必填 说明 值 任意(自动转为String) 是 需要被判断的原字符串。 suffix 任意(自动转为String) 是 后缀结尾规则。该参数可以是一个字符串或者是一个元素。 start Number 否 字符串检测的起始位置。 0表示第一个字符。-1表示倒数第一个字符。
end Number 否 字符串检测的结束位置。 0表示第一个字符。-1表示倒数第一个字符。
- 返回结果
如果字符串以指定后缀结尾则返回True,否则返回False。
- 函数示例
原始日志:
name: this is endswith!!!
加工规则:e_set("str_endswith",str_endswith(v("name"),"!"))
加工结果:name: this is endswith!!! str_endswith: True
str_startswith
- 函数格式
str_startswith(值, prefix, start, end)
说明 该函数为基本变参调用形式,请参见函数调用方式。 - 参数说明
参数名称 参数类型 是否必填 说明 值 任意(自动转为String) 是 需要被判断的原字符串。 prefix 任意(自动转为String) 是 前缀规则。该参数可以是一个字符串或者是一个元素。 start Number 否 字符串检测的起始位置。 0表示第一个字符。-1表示倒数第一个字符。
end Number 否 字符串检测的结束位置。 0表示第一个字符。-1表示倒数第一个字符。
- 返回结果
如果字符串以指定前缀开头则返回True,否则返回False。
- 函数示例
原始日志:
name: !! this is startwith
加工规则:e_set("str_startswith",str_startswith(v("name"),"!!"))
加工结果:name: !! this is startwith str_startswith: True
str_find
- 函数格式
str_find(值,str , begin, end)
说明 该函数为基本变参调用形式,请参见函数调用方式。 - 参数说明
参数名称 参数类型 是否必填 说明 值 任意(自动转为String) 是 需要被查找的原字符串。 str 任意(自动转为String) 是 指定查找的子字符串。 begin Number 否 开始索引的位置。 默认为0表示第一个字符。-1表示倒数第一个字符。
end Number 否 结束索引的位置。 默认为字符串的长度。0表示第一个字符。-1表示倒数第一个字符。
- 返回结果
返回指定子字符串在原字符串中的位置。如果指定的子字符串在原字符串中出现多次,只返回第一次出现的子字符串的位置。
- 函数示例
原始日志:
name: hello world
加工规则:e_set("str_find",str_find(v("name"),"h"))
加工结果:name: hello world str_find: 0
str_count
- 函数格式
str_count(值, sub, start,end)
说明 该函数为基本变参调用形式,请参见函数调用方式。 - 参数说明
参数名称 参数类型 是否必填 说明 值 任意(自动转为String) 是 被统计的原字符串。 sub 任意(自动转为String) 是 需要统计个数的字符。 start Number 否 字符串开始搜索的位置。 - 0(默认值):第一个字符。
- -1:最后一个字符。
end Number 否 字符串中结束搜索的位置。 - 0:第一个字符。
- -1(默认值):最后一个字符。
- 返回结果
返回指定字符出现的次数。
- 函数示例
原始日志:
name: this is really a string
加工规则:e_set("str_count",str_count(v("name"),"i"))
加工结果:name: this is really a string str_count: 3
str_rfind
- 函数格式
str_rfind(值, substr, beg, end)
说明 该函数为基本变参调用形式,请参见函数调用方式。 - 参数说明
参数名称 参数类型 是否必填 说明 值 任意(自动转为String) 是 被查找的原字符串。 substr 任意(自动转为String) 是 需要查找的字符。 beg Number 否 开始查找的位置,默认为0。 end Number 否 结束查找的位置,默认为字符串的长度。 - 返回结果
返回字符最后一次出现的位置。
- 函数示例
原始日志:
name: this is really a string
加工规则:e_set("str_rfind",str_rfind(v("name"),"i"))
加工结果:name: this is really a string str_rfind: 20
str_split
- 函数格式
str_split(值, sep=None, maxsplit=-1)
- 参数说明
参数名称 参数类型 是否必填 说明 值 任意(自动转为String) 是 需要被分割的原字符串。 sep Number 否 分隔符,None表示空格。 maxsplit Number 否 最大分裂数。-1 表示不限制。 - 返回结果
返回处理后的字符串。
- 函数示例:按照空格对content进行分隔。
原始日志:
content: hello world
加工规则:e_set("str_split",str_split(v("content")," "))
加工结果:content: hello world str_split: ["hello", "world"]
str_splitlines
- 函数格式
str_splitlines(值, keepends)
- 参数说明
参数名称 参数类型 是否必填 说明 值 任意(自动转为String) 是 需要被分割的原字符串。 keepends Bool 否 在输出结果里是否去掉换行符( \r
、\r\n
、\n
)。默认为False,不包含换行符,如果为True,则保留换行符。 - 返回结果
返回处理后的列表。
- 函数示例
- 示例1
原始日志:
content: ab c\n\nde fg\rkl\r\n
加工规则:e_set("str_splitlines",str_splitlines(v("content"),False))
加工结果:content: ab c\n\nde fg\rkl\r\n str_splitlines: ['ab c', '', 'de fg', 'kl']
- 示例2
原始日志:
content: ab c\n\nde fg\rkl\r\n
加工规则:e_set("str_splitlines",str_splitlines(v("content"),True))
加工结果:content: ab c\n\nde fg\rkl\r\n str_splitlines: ['ab c\n', '\n', 'de fg\r', 'kl\r\n']
- 示例1
str_partition
- 函数格式
str_partition(值,substr)
- 参数说明
参数名称 参数类型 是否必填 说明 值 任意(自动转为String) 是 需要被分割的字符串。 substr 任意(自动转为String) 否 指定的分隔符。 - 返回结果
返回分隔后的列表。
- 函数示例:对website按照
.
从左往右分隔成三部分。原始日志:website: www.aliyun.com
加工规则:e_set("str_partition",str_partition(v("website"),"."))
加工结果:website: www.aliyun.com str_partition: ["www", ".", "aliyun.com"]
str_rpartition
- 函数格式
str_rpartition(值,substr)
- 参数说明
参数名称 参数类型 是否必填 说明 值 任意(自动转为String) 是 需要被分割的原字符串。 substr 任意(自动转为String) 否 指定的分隔符。 - 返回结果
返回处理后的列表。
- 函数示例:对website按照
.
从右往左分隔成三部分。原始日志:website: www.aliyun.com
加工规则:e_set("str_partition",str_rpartition(v("website"),"."))
加工结果:website: www.aliyun.com str_partition: ["www.aliyun", ".", "com"]
str_center
- 函数格式
str_center(值, width, fillchar)
- 参数说明
参数名称 参数类型 是否必填 说明 值 任意(自动转为String) 是 需要被修改的原字符串。 width Number 是 填充后字符串的总长度。 fillchar 任意(自动转为String) 否 填充字符,默认为空格。 - 返回结果
返回处理后的字符串。说明 如果指定的填充后字符串长度小于原字符串长度则直接返回原字符串。
- 函数示例
- 示例1:使用
*
字符填充字符串。原始日志:center: this is center
加工规则:e_set("str_center", str_center(v("center"), 40, "*"))
加工结果:center: this is center str_center: *************this is center*************
- 示例2:使用空格填充字符串。
原始日志:
center: this is center
加工规则:e_set("str_center",str_center(v("center"),40))
加工结果:center: this is center str_center: this is center
- 示例1:使用
str_zfill
- 函数格式
str_zfill(值,width)
- 参数说明
参数名称 参数类型 是否必填 说明 值 任意(自动转为String) 是 需要被修改的原字符串。 width Number 是 填充后字符串的总长度。 - 返回结果
返回处理后的字符串。
- 函数示例
原始日志:
center: this is zfill
加工规则:e_set("str_zfill",str_zfill(v("center"),40))
加工结果:center:this is zfill str_zfill:000000000000000000000000000this is zfill
str_expandtabs
- 函数格式
str_expandtabs(值, tabsize)
- 参数说明
参数名称 参数类型 是否必填 说明 值 任意(自动转为String) 是 需要被修改的原字符串。 tabsize Number 是 指定转换后空格的字符数。 - 返回结果
返回处理后的字符串。
- 函数示例
- 示例1:把Logstash中的
\t
字符转为空格。原始日志:logstash: this is\tstring
加工规则:e_set("str_expandtabs",str_expandtabs(v("logstash")))
加工结果:logstash: this is\tstring str_expandtabs: this is string
- 示例2:把center中的
\t
字符转为空格。原始日志:{"center": "this is\tstring"}
加工规则:e_set("str_expandtabs",str_expandtabs(v("center"),16))
加工结果:center: this is\tstring str_expandtabs: this is string
- 示例1:把Logstash中的
str_ljust
- 函数格式
str_ljust(值, width, fillchar)
- 参数说明
参数名称 参数类型 是否必填 说明 值 任意(自动转为String) 是 需要被修改的原字符串。 width Number 是 填充后字符串的总长度。 fillchar 任意(自动转为String) 否 填充字符,默认为空格。 - 返回结果
返回处理后的字符串。说明 如果指定的填充后字符串长度小于原字符串长度则直接返回原字符串。
- 函数示例
- 示例1
原始日志:
content: this is ljust
加工规则:e_set("str_ljust",str_ljust(v("content"),20,"*"))
加工结果:content: this is ljust str_ljust: this is ljust*******
- 示例2
原始日志:
center: this is ljust
加工规则:e_set("str_ljust",str_ljust(v("center"),20,))
加工结果:center: this is ljust str_ljust: this is ljust
- 示例3:width宽度没有字符串长,则直接返回原字符串。
原始日志:
center: this is ljust
加工规则:e_set("str_ljust",str_ljust(v("center"),10,"*"))
加工结果:center: this is ljust str_ljust: this is ljust
- 示例1
str_rjust
- 函数格式
str_rjust(值, width, fillchar)
- 参数说明
参数名称 参数类型 是否必填 说明 值 任意(自动转为String) 是 需要被修改的原字符串。 width Number 是 填充后字符串的总长度。 fillchar 任意(自动转为String) 否 填充字符,默认为空格。 - 返回结果
返回处理后的字符串。说明 如果指定的填充后字符串长度小于原字符串长度则直接返回原字符串。
- 函数示例
原始日志:
center: this is rjust
加工规则:e_set("str_rjust",str_rjust(v("center"),20,"*"))
加工结果:center: this is rjust str_rjust: *******this is rjust
str_zip
- 函数格式
str_zip(值1, 值2, combine_sep=None, sep=None, quote=None, lparse=None, rparse=None)
- 参数说明
参数名称 参数类型 是否必填 说明 值1 任意(自动转为String) 是 需要被合并的值。 值2 任意(自动转为String) 是 需要被合并的值。 combine_sep 任意(自动转为String) 否 合并时元素之间的合并标识,默认为 #
。sep 任意(自动转为String) 否 合并后元素之间的分隔符,仅支持单个字符,默认为 ,
。quote 任意(自动转为String) 否 将合并后的元素括起来的字符,当值包含分隔符时需要使用,默认为 "
。lparse 任意(自动转为String) 否 指定 值1
中元素之间的分隔符和引用符,默认分隔符为,
,默认引用符为"
。格式为lparse=(',', '"')
。说明 引用符优先级高于分隔符。rparse 任意(自动转为String) 否 指定 值2
中元素之间的分隔符和引用符,默认分隔符为,
,默认引用符为"
。格式为rparse=(',', '"')
。说明 引用符优先级高于分隔符。 - 返回结果
返回合并后的字符串。
- 函数示例
- 示例1
原始日志:
website: wwww.aliyun.com escape_name: o
加工规则:e_set("combine",str_zip(v("website"),v("escape_name"), combine_sep="@"))
加工结果:website: wwww.aliyun.com escape_name: o combine: wwww.aliyun.com@o
- 示例2
原始日志:
website: wwww.aliyun.com escape_name: o
加工规则:e_set("combine",str_zip(v("website"),v("escape_name")))
加工结果:website: wwww.aliyun.com escape_name: o wwww.aliyun.com#o
- 示例3:sep的使用。
原始日志:
f1: a,b,c f2: x,y,z
加工规则:e_set("combine",str_zip(v("f1"), v("f2"), sep="|"))
加工结果:f1: a,b,c f2: x,y,z combine: a#x|b#y|c#z
- 示例4:quote的使用。
原始日志:
f1: "a,a", b, "c,c" f2: x, "y,y", z
加工规则:e_set("combine",str_zip(v("f1"), v("f2"), quote='|'))
加工结果:f1: "a,a", b, "c,c" f2: x, "y,y", z combine: |a,a#x|,|b#y,y|,|c,c#z|
- 示例5:不同长度的值。
原始日志:
f1: a,b f2: x,y,z
加工规则:e_set("combine",str_zip(v("f1"), v("f2")))
加工结果:f1: a,b f2: x,y,z combine: a#x,b#y
- 示例6:lparse和rparse的使用。
原始日志:
f1: a#b#c f2: x|y|z
加工规则:e_set("combine",str_zip(v("f1"), v("f2"), lparse=("#", '"'), rparse=("|", '"')))
加工结果:f1: a#b#c f2: x|y|z combine: a#x,b#y,c#z
- 示例7:lparse和rparse的使用。
原始日志:
f1: |a,a|, b, |c,c| f2: x, #y,y#, z
加工规则:e_set("combine",str_zip(v("f1"), v("f2"), lparse=(",", '|'), rparse=(",", '#')))
加工结果:f1: |a,a|, b, |c,c| f2: x, #y,y#, z combine: "a,a#x","b#y,y","c,c#z"
- 示例1
str_isalnum
- 函数格式
str_isalnum(值)
- 参数说明
参数名称 参数类型 是否必填 说明 值 任意(自动转为String) 是 需要被检测的字符串。 - 返回结果
返回True或False。
- 函数示例
原始日志:
content: 13
加工规则:e_set("str_isalnum",str_isalnum(v("content")))
加工结果:content: 13 str_isalnum: True
str_isalpha
- 函数格式
str_isalpha(值)
- 参数说明
参数名称 参数类型 是否必填 说明 值 任意(自动转为String) 是 需要被检测的字符串。 - 返回结果
返回True或False。
- 函数示例
原始日志:
content: 13
加工规则:e_set("str_isalpha",str_isalpha(v("content")))
加工结果:content: 13 str_isalpha: False
str_isascii
- 函数格式
str_isascii(值)
- 参数说明
参数名称 参数类型 是否必填 说明 值 任意(自动转为String) 是 需要被检测的字符串。 - 返回结果
返回True或False。
- 函数示例
原始日志:
content: asw123
加工规则:e_set("str_isascii",str_isascii(v("content")))
加工结果:content: asw123 str_isascii: True
str_isdecimal
- 函数格式
str_isdecimal(值)
- 参数说明
参数名称 参数类型 是否必填 说明 值 任意(自动转为String) 是 需要被检测的字符串。 - 返回结果
返回True或False。
- 函数示例
- 示例1
原始日志:
welcome: 你好
加工规则:e_set("str_isdecimal",str_isdecimal(v("welcome")))
加工结果:welcome: 你好 str_isdecimal: False
- 示例2
原始日志:
num: 123
加工规则:e_set("str_isdecimal",str_isdecimal(v("num")))
加工结果:num: 123 str_isdecimal: True
- 示例1
str_isdigit
- 函数格式
str_isdigit(值)
- 参数说明
参数名称 参数类型 是否必填 说明 值 任意(自动转为String) 是 需要被检测的字符串。 - 返回结果
返回True或False。
- 函数示例
原始日志:
content: 13
加工规则:e_set("str_isdigit",str_isdigit(v("content")))
加工结果:content: 13 str_isdigit: True
str_isidentifier
- 函数格式
str_isidentifier(值)
- 参数说明
参数名称 参数类型 是否必填 说明 值 任意(自动转为String) 是 需要被检测的字符串。 - 返回结果
返回True或False。
- 函数示例
原始日志:
class: class
加工规则:e_set("str_isidentifier",str_isidentifier(v("class")))
加工结果:class: class str_isidentifier: True
str_islower
- 函数格式
str_islower(值)
- 参数说明
参数名称 参数类型 是否必填 说明 值 任意(自动转为String) 是 需要被检测的字符串。 - 返回结果
返回True或False。
- 函数示例
原始日志:
lower: asds
加工规则:e_set("str_islower",str_islower(v("lower")))
加工结果:lower: asds str_islower: True
str_isnumeric
- 函数格式
str_isnumeric(值)
- 参数说明
参数名称 参数类型 是否必填 说明 值 任意(自动转为String) 是 需要被检测的字符串。 - 返回结果
返回True或False。
- 函数示例
原始日志:
num: 123
加工规则:e_set("str_isnumeric",str_isnumeric(v("num")))
加工结果:num: 123 str_isnumeric: True
str_isprintable
- 函数格式
str_isprintable(值)
- 参数说明
参数名称 参数类型 是否必填 说明 值 任意(自动转为String) 是 需要被检测的字符串。 - 返回结果
返回True或False。
- 函数示例
原始日志:
content: vs;,.as
加工规则:e_set("str_isprintable",str_isprintable(v("content")))
加工结果:content: vs;,.as str_isprintable: True
str_isspace
- 函数格式
str_isspace(值)
- 参数说明
参数名称 参数类型 是否必填 说明 值 任意(自动转为String) 是 需要被检测的字符串。 - 返回结果
返回True或False。
- 函数示例
原始日志:
space: as afsd
加工规则:e_set("str_isspace",str_isspace(v("space")))
加工结果:space: as afsd str_isspace: False
str_istitle
- 函数格式
str_istitle(值)
- 参数说明
参数名称 参数类型 是否必填 说明 值 任意(自动转为String) 是 需要被检测的字符串。 - 返回结果
返回True或False。
- 函数示例
原始日志:
title: Alex
加工规则:e_set("str_istitle",str_istitle(v("title")))
加工结果:title: Alex str_istitle: True
str_isupper
- 函数格式
str_isupper(值)
- 参数说明
参数名称 参数类型 是否必填 说明 值 任意(自动转为String) 是 需要被检测的字符串。 - 返回结果
返回True或False。
- 函数示例
原始日志:
content: ASSD
加工规则:e_set("str_isupper",str_isupper(v("content")))
加工结果:content: ASSD str_isupper: True
str_uuid
- 函数格式
str_uuid(lower=True)
- 参数说明
参数名称 参数类型 是否必填 说明 lower Bool 否 生成的uuid中的字母是否是小写。默认为True表示小写。 - 返回结果
返回uuid码。
- 函数示例
- 示例1
原始日志:
content: I am Iron man
加工规则:e_set("UUID",str_uuid())
加工结果:content: I am Iron man UUID: e9fcd6b0-b970-11ec-979d-0f7041e65ab8
- 示例2
原始日志:
content: I am Iron man
加工规则:e_set("UUID",str_uuid(lower=False))
加工结果:content: I am Iron man UUID: 0649211E-B971-11EC-A258-E71F0A2930C5
- 示例1