You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@nifi.apache.org by Igor Kravzov <ig...@gmail.com> on 2016/04/27 00:10:07 UTC

Help with replace method

Attached please find the test template. NiFi 0.6.1
I am trying to replace " with \" in a text.  So "Here "we" go" should
become \"Here \"we\" go\"


The call is in ReplaceText
processor: {"test":"${teststr:replace('"','\\"')}"}
teststr cerated in UpdateAttribute.

>From some reason unable to make it working. What can be wrong?

Thanks in advance.

Re: Help with replace method

Posted by Igor Kravzov <ig...@gmail.com>.
Sorry for late response.
Thanks Joe. I will take a look.
So if I want to replace also new line '\n' with character representation
"\n" I will need to do this
{"test":"${teststr:replaceAll('"','\\\\"'):replaceAll('\n',  '\\\\n'}"}.
Correct?


On Wed, Apr 27, 2016 at 12:19 AM, Joe Percivall <jo...@yahoo.com>
wrote:

> Hello Igor,
>
> I got your template working by using the below replacement string and
> changing the "Replacement Strategy" to "Always Replace". I've attached a
> template that works for me.
>
> {"test":"${teststr:replaceAll('"','\\\\"')}"}
>
>
> The backslashes are a bit weird because they escape characters and are
> used to escape themselves. So when you're trying to use them explicitly it
> can lead needing to repeat them multiple times (in this case 4).
>
> Hope this helps,
> Joe
> - - - - - -
> Joseph Percivall
> linkedin.com/in/Percivall
> e: joepercivall@yahoo.com
>
>
>
> On Tuesday, April 26, 2016 6:10 PM, Igor Kravzov <ig...@gmail.com>
> wrote:
>
>
>
> Attached please find the test template. NiFi 0.6.1I am trying to replace "
> with \" in a text.  So "Here "we" go" should become \"Here \"we\" go\"
>
>
> The call is in ReplaceText processor:
> {"test":"${teststr:replace('"','\\"')}"}
> teststr cerated in UpdateAttribute.
>
>
> From some reason unable to make it working. What can be wrong?
>
> Thanks in advance.
>

Re: Help with replace method

Posted by Igor Kravzov <ig...@gmail.com>.
Thanks Joe. It worked great.

On Wed, Apr 27, 2016 at 12:19 AM, Joe Percivall <jo...@yahoo.com>
wrote:

> Hello Igor,
>
> I got your template working by using the below replacement string and
> changing the "Replacement Strategy" to "Always Replace". I've attached a
> template that works for me.
>
> {"test":"${teststr:replaceAll('"','\\\\"')}"}
>
>
> The backslashes are a bit weird because they escape characters and are
> used to escape themselves. So when you're trying to use them explicitly it
> can lead needing to repeat them multiple times (in this case 4).
>
> Hope this helps,
> Joe
> - - - - - -
> Joseph Percivall
> linkedin.com/in/Percivall
> e: joepercivall@yahoo.com
>
>
>
> On Tuesday, April 26, 2016 6:10 PM, Igor Kravzov <ig...@gmail.com>
> wrote:
>
>
>
> Attached please find the test template. NiFi 0.6.1I am trying to replace "
> with \" in a text.  So "Here "we" go" should become \"Here \"we\" go\"
>
>
> The call is in ReplaceText processor:
> {"test":"${teststr:replace('"','\\"')}"}
> teststr cerated in UpdateAttribute.
>
>
> From some reason unable to make it working. What can be wrong?
>
> Thanks in advance.
>

Re: Help with replace method

Posted by Joe Percivall <jo...@yahoo.com>.
Hello Igor,

I got your template working by using the below replacement string and changing the "Replacement Strategy" to "Always Replace". I've attached a template that works for me.

{"test":"${teststr:replaceAll('"','\\\\"')}"}


The backslashes are a bit weird because they escape characters and are used to escape themselves. So when you're trying to use them explicitly it can lead needing to repeat them multiple times (in this case 4).

Hope this helps,
Joe
- - - - - - 
Joseph Percivall
linkedin.com/in/Percivall
e: joepercivall@yahoo.com



On Tuesday, April 26, 2016 6:10 PM, Igor Kravzov <ig...@gmail.com> wrote:



Attached please find the test template. NiFi 0.6.1I am trying to replace " with \" in a text.  So "Here "we" go" should become \"Here \"we\" go\"


The call is in ReplaceText processor: {"test":"${teststr:replace('"','\\"')}"}
teststr cerated in UpdateAttribute.


>From some reason unable to make it working. What can be wrong?

Thanks in advance.