cancel
Showing results for 
Search instead for 
Did you mean: 
Workflow Hero

Exclude text from a regular expression

Greetings,

I am using Nintex On-Prem for SharePoint 2010. I am currently working on an  multiple approver Lazy Approval workflow. My goal is to extract the approver name and approver comments. I can capture the comments however when I do I get the text of the email stored in the variable as well. I need some assistance in creating a regular expression to strip out everything after the approval comments. I'm and admin and normally this would go to our developer who is out. The brief version of the text is here:

BIZ\DornKev -LazyApproval by MyEmailAddress Approve
Comment 1

From: Approvals-UAT@sharepoint-uat.[mailto:Approvals-UAT@sharepoint-uat.
Sent: Wednesday, July 05, 2017 9:35 AM
To: Kevin Dorn <kevin.dorn@
Subject: Approval Required [#DDDZPKAQKNSJ#]

*******TEST SITE******
Workflow Notification
________________________________

You can approve this item by replying to this email with one of the following answers on the first line of the email:

Approve 

Below this is the text of the email that lists out item specific data that goes to the approver.

My current RegEx Pattern is 

Replace/Ignore Case

([\w\s,]+)\s\([\w\s]+\)\s(?:[\d:.\/\s\w\-]+)\s\([\w\s,]+\)\s(?<Comment>.*)

Replacement text Comment : "${Comment}"

Can someone guide me as to how to craft a RegEx that grabs everything before the FROM line above?

Any help is greatly appreciated

Kevin

Labels: (1)
Reply
4 Replies
Workflow Hero

Re: Exclude text from a regular expression

Hello Kevin Dorn‌ – the following .NET Regex expression will find all characters leading up to the "From" string.

Is this what you're looking for? Depending on your string variable, you may need to also clean-up new-line characters before performing the RegEx extraction.

Accept as Solution Reply
Workflow Hero

Re: Exclude text from a regular expression

I may be wrong here, but that only took the last "FROM" and then matched the line before it.

Meaning it grabbed "Can someone guide me as to how to craft a RegEx that grabs everything before the " but not "BIZ\DornKev -LazyApproval by MyEmailAddress Approve
Comment 1". 

So it seems like this would only work as long as nobody put the word "FROM" somewhere in the email.

0 Kudos
Accept as Solution Reply
Workflow Hero

Re: Exclude text from a regular expression

So you can add additional ":" character, so in the end you would have: .+?(?=From\Smiley Happy to be more sure

Regards, Tomasz Poszytek
0 Kudos
Accept as Solution Reply
Workflow Hero

Re: Exclude text from a regular expression

Judging from the comments above, you'd like to get the text between the "Approve" (immediately after the respondents email address) and the "From" text that is created whenever you receive an email reply... or at least I think that's the text that you'd like. 

Either way, here is the regex that will get it. 

(?<=approve|reject)[\s\S]+(?=FromSmiley Happy

Here is a visual of what you'll capture (highlighted in blue): 

This should also work in the event that they Reject / reject using this same method. Please note the case insensitivity flag (/i). You'll also probably need to trim anything grabbed with this method (using the Build String action) just to make sure that the whitespace is removed correctly. 

Is this what you were trying to do? 

if not, could you highlight the specific text that you're looking to grab? 


Accept as Solution Reply