ReplaceText处理器配置

时间:2016-04-24 16:29:08

标签: regex apache-nifi

我在正则表达式方面不是那么好。 执行以下操作的正确配置是什么;

  1. 从文本中删除反斜杠。
  2. 替换" {与{
  3. 替换}"用}
  4. 基本上我需要清除转义的JSON。

    像以前一样:

     "{\"hashtags\":[{\"text\":\"Apple\",\"indices\":[45,51]}],\"urls\":[{\"url\":\"\",\"expanded_url\":\"\",\"display_url\":\"owler.us/abdLas\",\"indices\":[64,87]}],\"user_mentions\":[],\"symbols\":[{\"text\":\"AAPL\",\"indices\":[88,93]}]}",
    

    后:

    {"hashtags":[{"text":"Apple","indices":[45,51]}],"urls":[{"url":"","expanded_url":"","display_url":"owler.us/abdLas","indices":[64,87]}],"user_mentions":[],"symbols":[{"text":"AAPL","indices":[88,93]}]},
    

    提前致谢。

2 个答案:

答案 0 :(得分:1)

来自NiFi用户组的这个建议很好: 3一个接一个地替换文本处理器:

  1. 搜索值:\ 替换值:空字符串集
  2. 2。 搜索值:“{ 替换值:{

    3。 搜索值:}“ 替换值:}

答案 1 :(得分:0)

您可以使用:

replaceAll("\"[{]", "{");
replaceAll("[}]\"", "}");

没有必要逃避这种反斜杠,因为它不是正则表达式反斜杠。

解释

  • \"与文字"匹配。

  • [}]}匹配。我选择使用括号而不是邪恶的Java转义转义。

相关问题