How to replace few keywords in a string with the help of Regex without using String replacement simple function.

How to replace few keywords in a string with the help of Regex without using String replacement simple function.

Use Case Description

“Hello Mr/Ms/Mrs <first_name> <last_name>, we would like to invite you to our product launch event next week on <day_of_week>. Please confirm by the end of the current week.”
In this given text I want to replace <first_name> with “Arslan”, <last_name> with “Bhatti” and <day_of_week> with “Sunday”. How to solve this use case with the help of Regex. I don’t want to use the simple Replace function of string.

AS-IS WORKFLOW, TO-BE WORKFLOW

-

Other information about the use case

Industry categories for this use case: Other Sector

Skill level required: Intermediate

UiPath Products that were used: UiPath Studio

Other applications that were used: -

Other resources: -

What is the top ROI driver for this use case?: Accelerate growth and operational efficiency

You can find text using regex then there is a find and replace activity

This will give <first_name> then use find and replace activity to find this text and replace it with custom names

OUTPUT :

here i have done for the first name

Regards,

Can you use String.Format method instead?

first_name = "Arslan"
last_name = "Bhatti"
day_of_week = "Sunday"
my_text = "Hello Mr/Ms/Mrs {0} {1}, we would like to invite you to our product launch event next week on {2}. Please confirm by the end of the current week."
formated_text = string.format(my_text, first_name, last_name, day_of_week)

Cheers

1 Like

@Arslan.Bhatti If your project is of Windows dependency, you can also do:

formattedText = $"Hello Mr/Ms/Mrs {firstName} {lastName}, we would like to invite you to our product launch event next week on {dayOfWeek}. Please confirm by the end of the current week."