Find exact Match and replace the tex file

Hi Every one,

Can someone help me find the exact match and replace the text?

In my text document, I’ve below texts. I wanted to find an exact match the word (?PipinInstruction1) replace with “Hameed”
The same case for (
?PipinInstruction15) replaces with “Hello”.

When I try to replace I got the below error to refer to screenshot. Also, I tried to find the exact match with regex still it’s matching with all the cases, can someone help out with this.

Actually, I am in the data table, and (*?PipinInstruction1) each row the value will change.

*?PipinInstruction1
*?PipinInstruction1 SOME TEXT
*?PipinInstruction15
*?PipinInstruction19 SOME TEXT
image

HI @Shagoul_Hameed

Try this expression

System.Text.RegularExpressions.Regex.Replace(Inputtxt,".*\d+","Hameed").ToString

image

Look into the XAML file
ReplaceText.xaml (6.0 KB)

Regards
Gokul

Hi,

Can you try the following expression?

System.Text.RegularExpressions.Regex.Replace(yourString,"\*\?PipinInstruction\d+","Hameed")

Regards,

Hi Gokul,

thanks for the response but still it’s replacing the below texts, it should not replace the below two as am replacing “Hameed” only for (?PipinInstruction1) not (?PipinInstruction15,*?PipinInstruction19 SOME TEXT)

*?PipinInstruction15
*?PipinInstruction19 SOME TEXT

Hi Yoichi,

I got the below error when I use this expression.

image

Hi,

System.Text.RegularExpressions.Regex.Replace(yourString,"\*\?PipinInstruction\d+","Hameed")

The above expression returns string which is replaced target string to “Hammed”.
If you want to check the target string is contained in condition of IF activity, can you try IsMatch activity as the following?

System.Text.RegularExpressions.Regex.IsMatch(yourString,"\*\?PipinInstruction\d+")

Regards,

dear all,

It’s not worked it’s replacing as “hameed” everywhere “*?PipinInstruction1” in the txt file.

Do we’ve any alternative solution?

Actually, the concept is, am running in a loop from the data table, for example, I’ve 4 rows each row I’ve found an exact match from column A and replaced with column B value.

However, the problem is when run 1st iteration it’s replaced correctly, with the above solution you shared. still, it’s replaced as “hameed” for ro3# & row#4.

ID Colum A Colum B
1 *?PipinInstruction1 Hameed
2 *?PipinInstruction1 SOME TEXT Shagoul
3 *?PipinInstruction15 RAJ
4 *?PipinInstruction19 SOME TEXT Gokul

Hi,

For understanding your requirement correctly, can you share your input string and expected string? It’s better if you can share the above as file.

Regards,

PFA…

Row1 = *?PipinInstruction1 is my input output should be “Hameed”
Row3 = *?PipinInstruction15 is my input output should be “RAJ”

Book1.xlsx (9.8 KB)

Hi,

Do you want to update the excel sheet? If so, the following will work. Can you try this?

Sample20220324-2.zip (9.8 KB)

Regards,

Dear Yoichi

Thank you but I want to find and replace it on txt file not the excel file.

So I will check the value from excel and I read the text file and I found an exact match then I should replace in the text file

Hi,

If possible, can you share your input text file and expected result text file? It’s no problem if dummy data.

Regards,

Yes , sure… PFA…
txt.txt (112 Bytes)

Hi,

Thanks.
Is this an input file? I’m glad if you can also share expected result text file.

Regards,

Sure, Attaching both input and result text files.
REsult.txt (63 Bytes)
txt.txt (121 Bytes)

Hi,

Thank you for sharing. Can you try the following?

Note: I modified master xlsx sheet as the following.

img20220324-5-1

Sample20220324-2v2.zip (10.1 KB)

Regards,

1 Like

Dear, Yoichi

Thanks a ton :blush: this will help me a lot, thanks you so much for the support​:blush:

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.