在每第 4 个 number/digit Oracle 11G 后添加一个 space

adding a space after each 4th number/digit Oracle 11G

我正在尝试让 space 进入每 4 个 number/digit(不是字符)。这是我想出的:

  newStudentNumber := regexp_replace(newStudentNumber, '[[:digit:]](....)', ' ');
  dbms_output.put_line(newStudentNumber);

结果:

NL 2345 7894  TUE

我真正想要的是:

NL 1234 5678 944 TUE

我的代码用 space 栏替换每第 4 位的数字,而不是像上面想要的结果那样添加 space。

谁能给我解释一下?

提前致谢

您可以使用以下正则表达式..

([[:digit:]]{4})

并替换为您现在正在做的事情.. (space)

Why yours is not working?

您的正则表达式匹配一个数字并捕获接下来的 4 个字符(不仅是数字)。所以..当你进行替换时..匹配但未捕获的数字也会被替换..而不是因为它无法插入。

输入的解释 = NL 12345678944 TUE 和正则表达式 = [[:digit:]](....):

NL 12345678944 TUE   (it will match digit "1" and captures "2345")

DEMO