How to remove date and replace it with void (null) in UiPath Studio using RegEx?
I have this statement as a problem statement which is given below:
Date: 27.07.2023
Pages: 2
Requested by: N_RAHUL
Here need to change Date “27.07.2023” with Null
and also Requested by “N_RAHUL” to Null
Kindly help me how to do this using RegEx in UiPath???
Replies with screenshots will be appreciated. Thank you in advance!
Hi @Yugandhara_Shirbhate
Assign activity: modifiedText = System.Text.RegularExpressions.Regex.Replace(inputText, "Date:\s\d{2}\.\d{2}\.\d{4}", "Date: Null")
Assign activity: modifiedText = System.Text.RegularExpressions.Regex.Replace(modifiedText, "Requested by:\s\w+", "Requested by: Null")
The regular expressions used in the “Assign” activity are as follows:
For the date: "Date:\s\d{2}\.\d{2}\.\d{4}"
Explanation:
Date:
: Matches the literal text “Date:”.
\s
: Matches a whitespace character (space).
\d{2}
: Matches two digits.
\.
: Matches a literal period (dot).
\d{4}
: Matches four digits.
For “Requested by” value: "Requested by:\s\w+"
Explanation:
Requested by:
: Matches the literal text “Requested by:”.
\s
: Matches a whitespace character (space).
\w+
: Matches one or more word characters (letters, digits, or underscores).
These regular expressions identify the parts of the input text that you want to replace and replace them with “Null”.
Hope it helps!!
1 Like
Both assign activities are named as “modifiedText” in the above statement…Is that correct?
postwick
(Paul Ostwick)
July 31, 2023, 5:17pm
4
You could just do…
Assign inputText = System.Text.RegularExpressions.Regex.Replace(inputText, "Date:\s\d{2}\.\d{2}\.\d{4}", "Date: Null")
Assign inputText = System.Text.RegularExpressions.Regex.Replace(inputText, "Requested by:\s\w+", "Requested by: Null")
I see so many people overcomplicating things by creating extra variables for no reason.
1 Like
postwick
(Paul Ostwick)
July 31, 2023, 5:19pm
6
You could also do it all in one statement…
Assign inputText = System.Text.RegularExpressions.Regex.Replace(System.Text.RegularExpressions.Regex.Replace(inputText, "Requested by:\s\w+", "Requested by: Null"), "Date:\s\d{2}\.\d{2}\.\d{4}", "Date: Null")
1 Like
vrdabberu
(Varunraj Dabberu)
July 31, 2023, 5:20pm
7
@Yugandhara_Shirbhate
System.Text.RegularExpressions.Regex.Replace(yourinputstring, "((?<=Date:\s+)\d+\.\d+\.\d+)", "Null")
System.Text.RegularExpressions.Regex.Replace(yourinputstring, "((?<=Requested by:\s+)\w+)", "Null")
Hope it helps
1 Like
Ok will try and let you know…
lrtetala
(Lakshman Reddy)
July 31, 2023, 5:21pm
9
Hi @Yugandhara_Shirbhate
Try this
Date= System.Text.RegularExpressions.Regex.Replace(inputText, "\d{2}\.\d{2}\.\d{4}", "Null")
Name = System.Text.RegularExpressions.Regex.Replace(inputTextDateReplaced, "(?<=Requested by: )\w+", "Null")
1 Like
vrdabberu
(Varunraj Dabberu)
July 31, 2023, 5:28pm
10
@Yugandhara_Shirbhate
Try the below regex expressions
System.Text.RegularExpressions.Regex.Replace(yourinputstring, "((?<=Date:\s+)\d+\.\d+\.\d+)", "Null")
System.Text.RegularExpressions.Regex.Replace(yourinputstring, "((?<=Requested by:\s+)\w+)", "Null")
Hope it works!!
1 Like
Thank you so so very much @postwick , @pravallikapaluri , @lrtetala , @vrdabberu for all your efforts and solutions. It worked for me!!! #Grateful
Cheers!
1 Like
@Yugandhara_Shirbhate
Welcome.
Happy automation.
1 Like
@Yugandhara_Shirbhate
If you find solution,mark it as solution to close the Loop
Regards
1 Like
Have one more question…
What if the date changed?.. from 27.07.2023 to any other date? (because I’ve told that date will keeps on changing as that particular document will get downloaded at any date, in which we need to replace date by null)
For that please tell me the RegEx to be used in assign activity
@Yugandhara_Shirbhate
Even though the date changes.
I think it will be in the same format and same place right. So,it will extract with same above solution
1 Like
Yes.
Okay. Thanks a lot!!! @pravallikapaluri
system
(system)
Closed
August 3, 2023, 6:23pm
17
This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.