Support Questions

Find answers, ask questions, and share your expertise

ReplaceTextWithMapping to replace value with space

avatar
Explorer

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

1 ACCEPTED SOLUTION

avatar
Master Mentor

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

 

View solution in original post

2 REPLIES 2

avatar
Master Mentor

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

 

avatar
Explorer

Thank you. It really helps 😃