Skip to main content
tsunbonyu
Gold ⭐️
October 5, 2019
Solved

ReplaceTextWithMapping to replace value with space

Hi,

 

I try to replace text with space using ReplaceTextWithMapping processor. I have file with multiple lines

 

"action":"account sing up"
"action":"account sign in"
"action":"account sign out"

 

And I have a mapping file with \t separating the search value and replace value

 

 

account sing up    asu
account sign in asi
account sign out aso

 

 

Regular expressions "action":"(.*)"

Matching group: 1

 

Result

 

"action":"account sing up"
"action":"account sign in"
"action":"account sign out"

 

Expected:

 

"action":"asu"
"action":"asi"
"action":"aso"

 

 

Does anyone know what I did wrong?

 

Thanks

David

MattWho
MattWhoAnswer
Titanium ⭐️⭐️⭐️
October 9, 2019

Hello David,

 

The ReplaceTextWithMapping processor has been around for some time now and its design is rather simplistic in its current implementation. It is designed to match a simple regex that will map one group of non-whitespace characters to another group of characters (can have white space and back references).

 

in your example you are matching on a a set of characters that contains whitespaces.

 

If you were to add a replaceText processor to your flow to replace all the whitespace with a non-whitespace character like "-", then it will work. sample ReplaceText processor configuration:

Screen Shot 2019-10-09 at 1.42.06 PM.png
Your mapping file would of course then be based off this change:

account-sing-up	asu
account-sign-in asi
account-sign-out aso

 

the resulting mapping would then work:

Screen Shot 2019-10-09 at 1.46.24 PM.png

 

Thank you,

Matt

 

2 replies

MattWho
Titanium ⭐️⭐️⭐️
MattWhoAnswer
Titanium ⭐️⭐️⭐️
October 9, 2019

Hello David,

 

The ReplaceTextWithMapping processor has been around for some time now and its design is rather simplistic in its current implementation. It is designed to match a simple regex that will map one group of non-whitespace characters to another group of characters (can have white space and back references).

 

in your example you are matching on a a set of characters that contains whitespaces.

 

If you were to add a replaceText processor to your flow to replace all the whitespace with a non-whitespace character like "-", then it will work. sample ReplaceText processor configuration:

Screen Shot 2019-10-09 at 1.42.06 PM.png
Your mapping file would of course then be based off this change:

account-sing-up	asu
account-sign-in asi
account-sign-out aso

 

the resulting mapping would then work:

Screen Shot 2019-10-09 at 1.46.24 PM.png

 

Thank you,

Matt

 

Translate
tsunbonyu
tsunbonyuAuthor
Gold ⭐️
October 9, 2019

Thank you. It really helps 😃

Translate