在 KDB+/Q 中将多个白色 space 减少为单个 space

Reduce multiple whitespaces to a single space in KDB+/Q

"a b""a b"

ssr["a         b";"[ ]+";" "]

好像不行。 谢谢!

您可以使用以下将每个重复的 space 视为一对, 然后使用 over,'replaces' 这些与单个 space.

q)x:"This         is    a    test"

q)(" "sv"  "vs)/[x]

"This is a test"

可以比使用 vssv 更有效地执行此操作。使用副词 each-prior ':

{x where not(and':)null x}"This         is    a    test"
"This is a test"

您可以使用 ssr/ 上的副词来连续删除两个空格的块:

ssr[;"  ";" "]/["This         is    a    test"]
"This is a test"

由于可用的正则表达式选项有限,您提供的示例失败,在此序列中使用 + "[ ]+" 是一个不受支持的操作示例。您可以在 kx wiki 上阅读有关 regex in q 的更多信息。