PDI 的 "Replace in String" 步骤,使用正则表达式替换两次

PDI's "Replace in String" step with regex doing replace twice

我想做的只是将参数连接到我现有的字符串“./executable.sh”,以便输出行集看起来像这样

./executable.sh argument1
./executable.sh argument3
./executable.sh argument2
  ...
  ...

下面是 "Replacement in string" 步骤。 搜索设置为 (.*) 。替换字段设置为 ./executable.sh $1

我得到的结果是:

./executable.sh argument1./executable.sh 
./executable.sh argument2./executable.sh 
./executable.sh argument3./executable.sh 

为什么我将初始字符串添加到替换的末尾?

谢谢。

这里的问题是你的正则表达式可以匹配在字符串之后匹配的 null/empty 字符串(即幕后引擎将字符串分成两部分:所有字符和终止空字符串,因此你得到两个被替换的匹配项。

为避免这种情况,您需要使用

(.+)

^(.*)$

(.+)模式匹配换行符以外的1个或多个字符,^(.*)$从字符串开头匹配换行符以外的0个或多个字符(^)到最后 ($)。第二种模式中的显式锚点有助于摆脱匹配输入末尾的空字符串。