Skip to main content
The trim_start_regex function removes all leading matches of a regular expression pattern from a string. Use this function to remove complex patterns from string beginnings, clean structured log prefixes, or normalize data with pattern-based trimming.

For users of other query languages

If you come from other query languages, this section explains how to adjust your existing queries to achieve the same results in APL.
In Splunk SPL, you use rex with mode=sed for pattern-based trimming. APL’s trim_start_regex provides a more direct approach.
| rex field=field mode=sed "s/^pattern//g"
In ANSI SQL, regex-based trimming requires database-specific functions. APL’s trim_start_regex provides standardized pattern-based trimming.
SELECT REGEXP_REPLACE(field, '^pattern', '') AS cleaned FROM logs;

Usage

Syntax

trim_start_regex(regex, text)

Parameters

NameTypeRequiredDescription
regexstringYesThe regular expression pattern to remove from the beginning.
textstringYesThe source string to trim.

Returns

Returns the source string with leading regex matches removed.

Use case examples

  • Log analysis
  • OpenTelemetry traces
  • Security logs
Remove protocol and host prefixes from full URLs to extract paths.Query
['sample-http-logs']
| extend full_url = strcat('https://api.example.com', uri)
| extend path_only = trim_start_regex('https?://[^/]+', full_url)
| summarize request_count = count() by path_only, method
| sort by request_count desc
| limit 10
Run in PlaygroundOutput
path_onlymethodrequest_count
/api/usersGET2341
/api/ordersPOST1987
This query strips protocol and host information from URLs to focus on path-based analysis.
  • trim_start: Removes leading characters. Use this for simple character-based trimming without regex.
  • trim_regex: Removes both leading and trailing regex matches. Use this for bidirectional pattern trimming.
  • replace_regex: Replaces regex matches. Use this when you need to replace patterns rather than just remove leading ones.
  • trim_end_regex: Removes trailing regex matches. Use this to trim patterns from the end.