如何在 NiFi 的内容处理器上为路由指定正则表达式?

How to specify regex for route on content processor in NiFi?

在nifi中,我是根据内容进行路由。我正在使用 nifi 的 RouteOnContent 那么,如何通过指定 regex

来路由

我输入的内容是:

{
"testreg":{
"test1":"test2",
"test3":"test4"
}
}

我想测试 testreg 整个内容(单词)是否出现在流文件内容中。 所以,我检查了

  1. testreg
  2. (testreg)
  3. .*testreg.*
  4. (.*testreg.*)

但它与内容不匹配,那么,Nifi 中使用的正确正则表达式是什么。

编辑: 检查我们正在寻找的模式是否被引号包围并后跟一个冒号非常有意义,因为模式 testreg 也可以简单地发生在其他地方。在这种情况下,我们得到最后一个匹配项,它不是 OK。所以,最终,这个:

[\s\S]*?(?<=")(testreg)(?=":)[\s\S]*?

将是我们正在寻找的理想答案。


也许,这里我们想要一个可以传递新行的表达式。我不太确定我们想要的输出是什么,但是我们可以开始针对一些选项进行测试,例如这些表达式:

[\s\S]*(testreg)[\s\S]*

[\w\W]*(testreg)[\w\W]* 

[\d\D]*(testreg)[\d\D]*

([\s\S].*?)(testreg)?

Demo

这个演示表明我们可以捕获并 return 我们想要的 testreg:

const regex = /[\s\S]*(testreg)[\s\S]*/gm;
const str = `{
"testreg":{
"test1":"test2",
"test3":"test4"
}
}`;
const subst = ``;

// The substituted value will be contained in the result variable
const result = str.replace(regex, subst);

console.log('Substitution result: ', result);