Replace Function

Seq 2025.1 introduces a Replace function that replaces occurrences of a pattern with a replacement. To replace the word March with the word April:

select Replace('The month is March', 'March', 'April') 
// 'The month is April'

The pattern may be a string or a regular expression. The following query removes the port number from a URI:

select Replace('https://example.com:7896/path', /:\d{1,5}/, '')
// 'https://example.com/path'

If pattern is a regular expression then capture groups can be referenced in the replacement by:

  • $0 - the entire match
  • $n - the nth capture group

The following query captures the street number ((\d+)) and the street name ((\w+)) and includes them in the replacement.

select Replace(
  '123 Main Street',
  /(\d+) (\w+) Street/,
  'Number: $1 Street Name: $2')
// 'Number: 123 Street Name: Main'

Like other string functions, Replace supports the ci (case-insensitive) modifier.

Seq 2025.1 is ready to try now: grab the binaries from https://datalust.co/download (look for the "preview" link) or pull datalust/seq:preview from Docker Hub.

Liam McLennan

Read more posts by this author.