Regex is not showing right rany result

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.

image

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!!

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!!

HI,

Can you clarify \n exist in the string as literal or linebreak? Which language do you use, VB or C#?

Regards,

None of them i working :(.

Hi @Ellen

Try this:

(?<=Best regards)([\s\S]+)[\r?\n]+([\s\S]+)

Hope it helps!!

Its not working in UiPath and that regex either working in regex101.com when i evaluate it.

@Ellen
Try it in Regex r website or assign acitvity. It will work fine.

Regards

Hi,

Can you share your data as file using WtiteTextFile activity?

Regards,

HI @Ellen

you can try with this

  1. 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

  1. 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”,“”)

Thanks a lot. That help. Genious you.

@Ellen
Welcome
Happy automation
Regards

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…

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

I have to use Regex on project så needed a solution on that.