Skip to content

ss, ssr

String search – and replace


String search

Syntax: x ss y, ss[x;y]


  • x is a string
  • y is a string of plain text, or a pattern

returns position/s of substring y within string x.

q)"We the people of the United States" ss "the"
3 17

It also supports some of the pattern-matching capabilities of like.

q)s:"toronto ontario"
q)s ss "ont"
3 8
q)s ss "[ir]o"
2 13
q)s ss "t?r"
0 10


String search and replace

Syntax: ssr[x;y;z]


  • x is a string
  • y is a pattern
  • z is a string or a function

returns x with each substring matching y replaced by:

  • z if z is a string
  • z[Y] where z is a function and Y is the matched substring
q)s:"toronto ontario"
q)ssr[s;"ont";"x"]      / replace "ont" by "x"
"torxo xario"
q)ssr[s;"t?r";upper]    / replace matches by their uppercase
"TORonto onTARio"

Basics: Strings
Knowledge Base: Regular expressions,