Ellen
(Ellen )
August 23, 2023, 7:13am
1
I have this in Mail body and I want a regex which give me User name and job title.
\nBest regards \nJorge Jensen
Assistent\n
Trying with a regex but its not working and showing no value and no error.
This regex is working on a invoke code activity but when I put the same regex in assign its showing no value.
Can someone help me to find the right regex.
Hi @Ellen
Try this
Best regards\s+([^\n]+)\s*\n\s*([^\n]+)
Or
(?<=Best regards\s)([^\sn]+)\s*\n\s*([^\n]+)
Hope it helps!!
Parvathy
(PS Parvathy)
August 23, 2023, 7:17am
3
Hi @Ellen
Try this Regex expression:
(?<=Best regards\s).*\n.*
Use this Assign activity:
System.Text.RegularExpressions.Regex.Match(yourstringinput,"(?<=Best regards\s).*\n.*").Value
Hope it helps!!
Yoichi
(Yoichi)
August 23, 2023, 7:21am
4
HI,
Can you clarify \n
exist in the string as literal or linebreak? Which language do you use, VB or C#?
Regards,
Ellen
(Ellen )
August 23, 2023, 7:29am
5
None of them i working :(.
Parvathy
(PS Parvathy)
August 23, 2023, 7:33am
6
Hi @Ellen
Try this:
(?<=Best regards)([\s\S]+)[\r?\n]+([\s\S]+)
Hope it helps!!
Ellen
(Ellen )
August 23, 2023, 7:38am
7
Its not working in UiPath and that regex either working in regex101.com when i evaluate it.
Parvathy
(PS Parvathy)
August 23, 2023, 7:43am
8
@Ellen
Try it in Regex r website or assign acitvity. It will work fine.
Regards
Yoichi
(Yoichi)
August 23, 2023, 7:45am
9
Hi,
Can you share your data as file using WtiteTextFile activity?
Regards,
HI @Ellen
you can try with this
str_Varaiable= Regex.Match(text,“(?<=Best regards)([\s\S]+)[\r?\n]+([\s\S]+)”).Value.Trim
and output =\nJorge Jensen
Assistent\n
in case if you required in single line
str_Varaiable=System.Text.RegularExpressions.Regex.Replace(Regex.Match(text,“(?<=Best regards)([\s\S]+)[\r?\n]+([\s\S]+)”).Value.Trim,“\r?\n”,“,”)
output = \nJorge Jensen,Assistent\n
for the reference you can see the screenshot
you can remove the \n also by same adding .replace at the end
str_Varaible= System.Text.RegularExpressions.Regex.Replace(Regex.Match(text,“(?<=Best regards)([\s\S]+)[\r?\n]+([\s\S]+)”).Value.Trim,“\r?\n”,“,”).Replace(“\n”,“”)
Ellen
(Ellen )
August 23, 2023, 10:37am
12
Thanks a lot. That help. Genious you.
@Ellen
Welcome
Happy automation
Regards
Ellen
(Ellen )
August 23, 2023, 12:59pm
14
It is not working right… I have mail text as:
Best regards
Jeorge Jensen
Assistant
You can not reply on that email.
With your this quote…
pravallikapaluri:
myPattern = Best regards\s+([^\n]+)\s*\n\s*([^\n]+)
myMatch = Regex.Match(myText, myPettern)
UserName = myMatch.groups(1).value
UserTitel = myMatch.groups(2).value
It give me out Name and job title… When I have name and titel in email – which is correct
but when I dont have job title then it shows the next line text on the place of title… which is “You can not reply on that email” … and that I do not want…
so regex should stop right after readig the next space and text… why groups(2).value is showing the 6 line value?
you can try this @Ellen
str_reg ="Best regards
Jeorge Jensen
Assistant"
str_reg.Split({“Best regards”},StringSplitOptions.RemoveEmptyEntries)(0).Trim
Ellen
(Ellen )
August 25, 2023, 6:29am
16
I have to use Regex on project så needed a solution on that.