How can I get this with Studio/Regex?

This is the body of an email:
Region: Netherlands&&

Site: Zoetermeer&&

Project: Not existing Team&&

Subject: Sign out licences&&

What do you want to achieve?:
Please sign out the following licenses

  • Inbound licenses
  • Outbound licenses (Interaction Dialer Add-On and Interaction Scripter)
  • Interaction Recorder Access licenses
    &&

I would like to catch everything between ": " and “&&”. So for instance: “Netherlands”, “Zoetermeer”, “Not existing Team” etc.
I used Regex-code for it: (?<=Region: ).*(?=&{2})
The result is saved as a IEnumerable.
I have tested this with a Write line (For example: ienumRegion(0).Value) and this works with Region, Site, Project and Subject.

For “What do you want to achieve?:” I used (?<=What do you want to achieve[?]:).*(?=&{2})
Also this result is saved as a IEnumerable
However if I test this with a Write Line With in it: ‘ienumAchieves(0).Value’ I receive this message: Object reference not set to an instance of an object.
What am I doing wrong?

Many thanks in advance!!!

Try with Substring.

Hey!

Try like this:

Assign Region = System.Text.RegularExpressions.RegEx.Match("InputStringOrVariable","(?<=Region: )[A-Za-z].*(?=&&)").ToString

Reference:

You can just change the region you can extract the remaining data

Use different Variables to store the different Data

Regards,
NaNi

I do not completely understand you. How do I write it?

Thanks! However this doesn’t work with “What do you want to achieve?:”…

Hey!

Before using the regex we need to import the namespaces from the import panel…

FYI:

ImportsRegEx

Then take one assign activity and use the regex which is mentioned above

Regards,
NaNi

I don’t think I understand you completely.

image

For strRegion I used
System.Text.RegularExpressions.RegEx.Match(“strBody”,“(?<=Region: )[A-Za-z].*(?=&&)”).ToString

When I add it to a data table I get a empty cell…

About the namespaces: I have got system.text.regularexpressions in my imports:
image

Hey!

StrBody is an veriable…

So we can remove the double quotation marks…

System.Text.RegularExpressions.RegEx.Match(strBody,“(?<=Region: )[A-Za-z].*(?=&&)”).ToString

Regards,
NaNi

Thanks that works, but not for strAchieves:
Therefor I used: System.Text.RegularExpressions.RegEx.Match(strBody,“(?<=What do you want to achieve[?]:)[A-Za-z].*(?=&&)”).ToString. The result is empty…
What am I doing wrong? Is it because this is multiline?

1 Like

Hey !

Try this:

Region:

StrRegion = System.Text.RegularExpressions.RegEx.Match(strBody,“(?<=Region: )[A-Za-z0-9].*(?=&&)”).ToString

Site:

StrSite = System.Text.RegularExpressions.RegEx.Match(strBody,“(?<=Site: )[A-Za-z0-9].*(?=&&)”).ToString

Project:

StrProject = System.Text.RegularExpressions.RegEx.Match(strBody,“(?<=Project: )[A-Za-z0-9].*(?=&&)”).ToString

Subject:

StrSubject = System.Text.RegularExpressions.RegEx.Match(strBody,“(?<=Subject: )[A-Za-z0-9].*(?=&&)”).ToString

Try this

Regards,
NaNi

Hello @100981 Try the attached workflow

Example.zip (3.4 KB)

Output

Capture

Thanks, this is helping me a lot!!! Just a small issue: the ending && after the input at “What do you want to achieve” is sometimes on a new line (Then your solution works great!! :smiley: ) but also sometimes right after the last character(Then it doesn’t work :frowning_face: ), like “licenses&&”.
Any idea how to solve this?
Again: many thanks in advance!!

As you can see I am not that familiar with RegEx. However I solved my last issue myself.
Thanks for all your help!!

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.