Removes all leading and trailing matches of the specified regular expression.


trim(regex, text)


  • regex: String or regular expression to be trimmed from the beginning and/or the end of text.
  • text: A string.


text after trimming matches of regex found in the beginning and/or the end of text.


Statement bellow trims substring from the start and the end of the string_to_trim:

let string_to_trim = @"--";
let substring = "--";
print string_to_trim = string_to_trim, trimmed_string = trim(substring,string_to_trim)
string_to_trim trimmed_string

Next statement trims all non-word characters from start and end of the string:

range x from 1 to 5 step 1
| project str = strcat("-  ","Te st",x,@"// $")
| extend trimmed_str = trim(@"[^\w]+",str)
str trimmed_str
- Te st1// $ Te st1
- Te st2// $ Te st2
- Te st3// $ Te st3
- Te st4// $ Te st4
- Te st5// $ Te st5