Support Portal

for ProcessRobot and WinAutomation

Start a new topic
Answered

Replacing a string of characters with the number of characters.

Hi, hopefully someone knows how to do this.

I am trying to create an automation that replaces a character with the number of times that character appears.

In particular i am trying to replace something like 'tony***smith' with 'tony.{3}smith'

Basically replacing the wildcards and changing the string into a regex i can search with. So whenever I copy something with wildcards, I can paste it with the new format.

Hopefully that is clear, anyone have a solution?

Thanks

 


Best Answer

Hello Jack,


There is an easy way to accomplish this.


First Parse the text to find the positions (indexes) of the character you want to replace. Make sure that you will configure the action in a way that all Occurrences are mapped in a list.


Then with the Replace Text, you could replace the characters with their number, by using regex.


Please see the image below for more info.


 


ADMIN
Answer

Hello Jack,


There is an easy way to accomplish this.


First Parse the text to find the positions (indexes) of the character you want to replace. Make sure that you will configure the action in a way that all Occurrences are mapped in a list.


Then with the Replace Text, you could replace the characters with their number, by using regex.


Please see the image below for more info.


 


1 person likes this

 Yes! Perfect, thank you so much!

ADMIN

You are welcome Jack. 


Keep Automating :) 

Hi guys,


I am trying to find if I can replace a named group for another value using "Replace text" action with 2 regex, one to find and the other to replace. I found that Here.

In a notepad++ I can do it with this:


Regex to find: (?'fev'fev)|(?'abr'abr)|(?'mai'mai)|(?'ago'ago)|(?'set'set)|(?'out'out)|(?'dez'dez)

Regex to replace: (?{fev}feb)(?{abr}apr)(?{mai}may)(?{ago}aug)(?{set}sep)(?{out}oct)(?{dez}dec)


Input Text: "05-fev-2020"

Output Text: "05-feb-2020"


But in WA I think it more like that ${fev:+feb} (February as example), but it doesnt work. This ${fev} is valid, it store the fev text, but I cant replace.


Why I am doing it?
I have a dates like "05-fev-2020" (fev because in pt-br February is Fevereiro), so I need to find "fev" and replace it for "feb" and in pt-br 7 months that start different on english.


fev feb

abr apr

mai may

ago aug

set sep

out oct

dez dec


Anyone know if i can do it with regex, please reply!!! For now I will do it in a dirty way. Split, Switch, Replace and Join.


Thank you

Login or Signup to post a comment