Support Questions
Find answers, ask questions, and share your expertise
Announcements
Alert: Welcome to the Unified Cloudera Community. Former HCC members be sure to read and learn how to activate your account here.

replacetext processor: replacing '$$$$' with '\$' while replacing content

Solved Go to solution
Highlighted

replacetext processor: replacing '$$$$' with '\$' while replacing content

New Contributor

I am trying to replace the content in the flowfile using replaceText processor.

If the attribute is "myattr" and I replace the content of the flowfile using replaceText processor with ${myattr}. I am seeing the below results

if myattr is "$$this is test$$", then the content of flowfile is replaced as "\$this is test\$"

if myttr is "\$$$this is test$$", then the content of flowfile is replaced as "\$\$this is test\$"

May I know how can I overcome the issue of '\'

1 ACCEPTED SOLUTION

Accepted Solutions

Re: replacetext processor: replacing '$$$$' with '\$' while replacing content

Super Guru

@Anil Reddy

if you are using

Replacement Strategy

Regex Replace

In ReplaceText processor, it will add \ before $ sign because $ is special character(end of line) character in Regular expression.

If you use

Replacement Strategy

Always Replace

this Strategy won't add any \ to before $ sign.

I'm not sure if you are going to achieve your desired result with Always Replace strategy.

What you can do to overcome \ issue is after your first Replace Text Processor(that adds \ before $) add another Replace text processor with below configs.

Search Value

\ //search for \(backslash) literal

Replacement Value

${literal('')}  //replace \ with empty

(or)

Instead of keeping above value(${literal('')}) you can click on check box that is shown below

56454-setemptystring.png

Both methods above will result same empty string as Replacement Value.

Maximum Buffer Size

1 MB 

Replacement Strategy

Regex Replace

Evaluation Mode

Entire text

Configs:-

56453-replace.png

Example:-

Input:-

\$\$\$\$\$\$\$\$hi\$\$\$\$\$\$\$\$

Output:-

$$$$$$$$hi$$$$$$$$

By using two Replace Text processors in series we are going to replace \ that is added in first replace text processor.

2 REPLIES 2

Re: replacetext processor: replacing '$$$$' with '\$' while replacing content

Super Guru

@Anil Reddy

if you are using

Replacement Strategy

Regex Replace

In ReplaceText processor, it will add \ before $ sign because $ is special character(end of line) character in Regular expression.

If you use

Replacement Strategy

Always Replace

this Strategy won't add any \ to before $ sign.

I'm not sure if you are going to achieve your desired result with Always Replace strategy.

What you can do to overcome \ issue is after your first Replace Text Processor(that adds \ before $) add another Replace text processor with below configs.

Search Value

\ //search for \(backslash) literal

Replacement Value

${literal('')}  //replace \ with empty

(or)

Instead of keeping above value(${literal('')}) you can click on check box that is shown below

56454-setemptystring.png

Both methods above will result same empty string as Replacement Value.

Maximum Buffer Size

1 MB 

Replacement Strategy

Regex Replace

Evaluation Mode

Entire text

Configs:-

56453-replace.png

Example:-

Input:-

\$\$\$\$\$\$\$\$hi\$\$\$\$\$\$\$\$

Output:-

$$$$$$$$hi$$$$$$$$

By using two Replace Text processors in series we are going to replace \ that is added in first replace text processor.

Re: replacetext processor: replacing '$$$$' with '\$' while replacing content

New Contributor

It works, Thanks alot @Shu