How do you handler parsing and substituting '[' and ']' characters in kdb+ strings?

61 views Asked by At

Example: I would like to substitute x[0] in the below string and change it to the character 'p'. This would expect the result to be tap. but it does not work since [ and ] are specially interpreted by kdb+ and I am not able to use backslash to escape their special meaning either.

ssr["tax[0]";"x[0]";"p"] /expected result tap.

How do you handle this case? I am writing a command parser where in I need to stick in parameters received in UI into a command template and substitute parameters which could be either x;y;z or x[0];x[1];x[2]. In the case of the latter searching and substituting x[0],x[1]...x[2]]...kind of case doesn't work using normal ssr.

1

There are 1 answers

0
cillianreilly On

Special characters can be matched by bracketing them as lists of alternatives https://code.kx.com/q/basics/regex/#matching-special-characters

q)ssr["tax[0]";"x[[]0[]]";"p"]
"tap"