Vorwärts
Es scheint, dass Sie mit einem JSON-String arbeiten, wäre es einfacher, mit einer solchen Zeichenfolge über ein JSON Parsing-Engine als JSON-Struktur zu arbeiten, ermöglicht die Erstellung von schwierigen Grenzfälle, die Parsing macht mit regulären Ausdrücken schwierig. Damit haben Sie sicher Ihre Gründe und ich bin nicht die Regex Police.
Beschreibung
einen solchen Ersatz zu tun wäre es die Teilstrings zu erfassen leichter Sie halten werden und die Teil Sie ersetzen möchten.
(\{"[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]+\})
mit Ersetzen: $1SomeText$3$4$5A2$7

Hinweis: Ich empfehle die folgenden Flags mit diesem Ausdruck mit: Case Insensitive und Dot passt auf alle Zeichen einschließlich der neuen Linien.
Exmaples
Live-Deno
Dieses Beispiel zeigt, wie der reguläre Ausdruck gegen Rohtext matches: https://regex101.com/r/vM1qE2/1
Quelle Text
{"field1" : "A",
"field2" : "A",
"field3": "A"
}
Nach Ersatz
{"field1" : "SomeText",
"field2" : "A",
"field3": "A2"
}
Erklärung
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
Hallo, vielen Dank für Ihre sehr ausführliche Antwort, sehr geschätzt. Ich benutze tatsächlich einen NiFi-Prozessor namens ReplaceTextWithMapping (siehe hier: https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi.processors.standard.ReplaceTextWithMapping/index.html) und ich scheine um passende Gruppen verwenden zu können (Matching group property), obwohl es scheint, dass ich nur eins nach dem anderen setzen kann. Ich habe ein paar Versuche gemacht, aber es funktioniert nicht in NiFi. – paranza
Das Dokument für ReplaceTextWithMapping besagt, dass das Ersetzungssystax eine Zahl ohne Dollarzeichen ist. Ich empfehle ReplaceText, das die Dollarsign + Number Combo für die Ersetzung von Werten verwendet. https://nifi.apache.org/docs/nifi-docs/components/org.apache.nifi.processors.standard.ReplaceText/index.html –
Ja, das war mein erster Schritt, aber über den Datenfluss zu ReplaceTextWithMapping verschoben Ich muss einige Mappings anwenden, die von externen Dateien kommen. Deshalb verwende ich ReplaceTextWithMapping und bin mir nicht sicher, ob mir etwas fehlt, aber es scheint nicht möglich zu sein, mit mehreren übereinstimmenden Gruppen zu arbeiten. Danke für Ihre Hilfe, geschätzt. – paranza