フォワード
あなたがJSON文字列で作業しているJSON構造を解析するなりにくいエッジケースを作成することができますよう、JSONの構文解析エンジンを経由して、このような文字列で動作するように容易になるだろうと思われます正規表現は難しい。それで、私はあなたの理由があると確信しています、そして、私は正規の警察ではありません。あなたがしておこうストリングと置き換えたい部分文字列をキャプチャするために容易になるだろう、このような交換を行うには
説明
。
(\{"[a-z0-9]+"\s*:\s*")([a-z0-9]+)("[,\r\n]+"[a-z0-9]+"\s*:\s*")([a-z0-9]+)("[,\r\n]+"[a-z0-9]+"\s*:\s*")([a-z0-9]+)("[,\r\n]+\})
と交換してください:$1SomeText$3$4$5A2$7
注:私はこの表現で、以下のフラグを使用することをお勧め:ケース小文字を区別しない、との点は、新しい行を含むすべての文字に一致します。
Exmaples
ライブ電王
この例では、正規表現は、あなたのソーステキストに対して一致する方法を示しています。 https://regex101.com/r/vM1qE2/1
ソーステキスト
{"field1" : "A",
"field2" : "A",
"field3": "A"
}
は、交換後
{"field1" : "SomeText",
"field2" : "A",
"field3": "A2"
}
説明
NODE EXPLANATION
----------------------------------------------------------------------
( group and capture to \1:
----------------------------------------------------------------------
\{ '{'
----------------------------------------------------------------------
" '"'
----------------------------------------------------------------------
[a-z0-9]+ any character of: 'a' to 'z', '0' to '9'
(1 or more times (matching the most
amount possible))
----------------------------------------------------------------------
" '"'
----------------------------------------------------------------------
\s* whitespace (\n, \r, \t, \f, and " ") (0
or more times (matching the most amount
possible))
----------------------------------------------------------------------
: ':'
----------------------------------------------------------------------
\s* whitespace (\n, \r, \t, \f, and " ") (0
or more times (matching the most amount
possible))
----------------------------------------------------------------------
" '"'
----------------------------------------------------------------------
) end of \1
----------------------------------------------------------------------
( group and capture to \2:
----------------------------------------------------------------------
[a-z0-9]+ any character of: 'a' to 'z', '0' to '9'
(1 or more times (matching the most
amount possible))
----------------------------------------------------------------------
) end of \2
----------------------------------------------------------------------
( group and capture to \3:
----------------------------------------------------------------------
" '"'
----------------------------------------------------------------------
[,\r\n]+ any character of: ',', '\r' (carriage
return), '\n' (newline) (1 or more times
(matching the most amount possible))
----------------------------------------------------------------------
" '"'
----------------------------------------------------------------------
[a-z0-9]+ any character of: 'a' to 'z', '0' to '9'
(1 or more times (matching the most
amount possible))
----------------------------------------------------------------------
" '"'
----------------------------------------------------------------------
\s* whitespace (\n, \r, \t, \f, and " ") (0
or more times (matching the most amount
possible))
----------------------------------------------------------------------
: ':'
----------------------------------------------------------------------
\s* whitespace (\n, \r, \t, \f, and " ") (0
or more times (matching the most amount
possible))
----------------------------------------------------------------------
" '"'
----------------------------------------------------------------------
) end of \3
----------------------------------------------------------------------
( group and capture to \4:
----------------------------------------------------------------------
[a-z0-9]+ any character of: 'a' to 'z', '0' to '9'
(1 or more times (matching the most
amount possible))
----------------------------------------------------------------------
) end of \4
----------------------------------------------------------------------
( group and capture to \5:
----------------------------------------------------------------------
" '"'
----------------------------------------------------------------------
[,\r\n]+ any character of: ',', '\r' (carriage
return), '\n' (newline) (1 or more times
(matching the most amount possible))
----------------------------------------------------------------------
" '"'
----------------------------------------------------------------------
[a-z0-9]+ any character of: 'a' to 'z', '0' to '9'
(1 or more times (matching the most
amount possible))
----------------------------------------------------------------------
" '"'
----------------------------------------------------------------------
\s* whitespace (\n, \r, \t, \f, and " ") (0
or more times (matching the most amount
possible))
----------------------------------------------------------------------
: ':'
----------------------------------------------------------------------
\s* whitespace (\n, \r, \t, \f, and " ") (0
or more times (matching the most amount
possible))
----------------------------------------------------------------------
" '"'
----------------------------------------------------------------------
) end of \5
----------------------------------------------------------------------
( group and capture to \6:
----------------------------------------------------------------------
[a-z0-9]+ any character of: 'a' to 'z', '0' to '9'
(1 or more times (matching the most
amount possible))
----------------------------------------------------------------------
) end of \6
----------------------------------------------------------------------
( group and capture to \7:
----------------------------------------------------------------------
" '"'
----------------------------------------------------------------------
[,\r\n]+ any character of: ',', '\r' (carriage
return), '\n' (newline) (1 or more times
(matching the most amount possible))
----------------------------------------------------------------------
\} '}'
----------------------------------------------------------------------
) end of \7
こんにちは、あなたの非常に詳細な応答のためのおかげで、はるかに高く評価。私は実際にReplaceTextWithMapping(https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi.processors.standard.ReplaceTextWithMapping/index.html参照)と呼ばれるNiFiプロセッサを使用しています。一致するグループ(一致するグループプロパティ)を使用できるようにするには、一度に1つしか設定できないようです。私はいくつかの試みをしましたが、NiFiではうまくいきません。 – paranza
ReplaceTextWithMappingのドキュメントでは、置換systaxがドル記号のない数字であることを示しています。私は、置換の値にdollarsign + Numberコンボを使用するReplaceTextを見てみることをお勧めします。 https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi.processors.standard.ReplaceText/index.html –
これは私の最初のステップでしたが、私のデータフローを通してReplaceTextWithMappingに移動しました外部ファイルからのマッピングを適用する必要があります。だから私はReplaceTextWithMappingを使用していると私は何かが不足しているかどうかはわかりませんが、複数の一致するグループで動作するようには思われません。おかげさまで、ありがとうございました。 – paranza