Regex to find the particular word and replace all the words next to it with *****

Input Text :

This is Sample PDF file
Date: 22-03-2024
Invoice Number:12345asdghhj

Expected output : Invoice Number: ***********

Sorry since i can’t upload the original PDF file. copied few text from the PDF file .
We are reading the PDF file and store into string varaible and trying to replace all the values next to Invoice Number:

Hi @Sathish_Kumar_S

Input = "Date: 22-03-2024"

Output = System.Text.RegularExpressions.Regex.Replace(Input,"[\d-]","*")

Regards

Hi @Sathish_Kumar_S

You can try the below expression with regex,

- Assign -> Output = System.Text.RegularExpressions.Regex.Replace(Input.toString, "Date:\d{2}\-\d{2}\-\d{4}", "Date: ***********")

Hope it helps!!

It not only date … it can be anything for example … We may have to find the “Invoice Number” and replace all the text next to it… Will this regex work ?

HI,

How about the following?

System.Text.RegularExpressions.Regex.Replace(yourString,"(?<=Date\s*:\s*)\S+",Function(m) new String("*"c,m.Value.Length))

Regards,

No it will not work for Invoice Number,

If your input for Invoice Number and Date as below,
Date: 22-03-2024
Invoice Number: Inv5214523

Then try the below regular expression it will work for both,

- Assign -> Output = System.Text.RegularExpressions.Regex.Replace(Input.ToString,"(?<=:\s?)[\S]+","*********")

Check the below image for better understanding,
image

Hope it helps!!

If you just want the invoice replaced, you can use the Replace Matchning Patterns-activity, and as pattern, use this Regex-expression:

^Invoice: (?<InvId>.*)$

The search need to be set to multi line.
IF you want to save The invoicenumber you can save it from The InvId group.