Reputation: 119
I am trying to replace a date format in all lines of text file using NiFi. The file looks like this:
ABCDE,20200619,23.8
FGHIJ,20200619,14.5
...
I am trying to do this using ReplaceText processor to change 20200619
to 2020-06-19
. I've made regex expression matching the date ((20\d{6},)
) and I have checked that it's working: when i write $1 TESTING,
in Replacement value
it works as expected (single line of file looks like ABCDE,20200619, TESTING,23.8
).
The problem is when I try to use Expression Language and :substring
function. This is my code in Replacement value
:
${$1:substring(0, 4)}-${$1:substring(4, 6)}-${$1:substring(6, 8)}
But I get following error:
It looks like the Expression Language can't access my $1
variable. How can I access my Regex Capturing Group variable inside Expression Language?
This is my processor:
Upvotes: 2
Views: 1997
Reputation: 119
I found the answer: when trying to access Regex Capturing Group inside ${...} we need to use it with apostrophes, so the code like this works:
${'$1':substring(0, 4)}-${'$1':substring(4, 6)}-${'$1':substring(6, 8)}
Upvotes: 9