trim_end()trim_end()

删除指定正则表达式的尾随匹配项。Removes trailing match of the specified regular expression.

语法Syntax

trim_end(regex, text)trim_end(regex, text)

参数Arguments

  • regex:要从 text 的结尾修剪的字符串或正则表达式regex: String or regular expression to be trimmed from the end of text.
  • text:一个字符串。text: A string.

返回Returns

修剪 text 结尾的 regex 匹配项后的 text。text after trimming matches of regex found in the end of text.

示例Example

以下语句从 string_to_trim 的结尾修剪 substring:Statement bellow trims substring from the end of string_to_trim:

let string_to_trim = @"bing.com";
let substring = ".com";
print string_to_trim = string_to_trim,trimmed_string = trim_end(substring,string_to_trim)
string_to_trimstring_to_trim trimmed_stringtrimmed_string
bing.combing.com bingbing

下一条语句从字符串的结尾修剪所有非单词字符:Next statement trims all non-word characters from the end of the string:

print str = strcat("-  ","Te st",x,@"// $")
| extend trimmed_str = trim_end(@"[^\w]+",str)
strstr trimmed_strtrimmed_str
- Te st1// $- Te st1// $ - Te st1- Te st1
- Te st2// $- Te st2// $ - Te st2- Te st2
- Te st3// $- Te st3// $ - Te st3- Te st3
- Te st4// $- Te st4// $ - Te st4- Te st4
- Te st5// $- Te st5// $ - Te st5- Te st5