I need regular expression for extracting info from workflow comments


Badge +3

I have workflow that is sent to multiple approvers with First response applies.  From the workflow comments that  I store in the field, I would like to extract only the information about user and time the response was sent (approve or reject).  Based on my research this is doable using a regular expression. I need help with creating the regular expression pattern. Help!


22 replies

Userlevel 7
Badge +11

Hi Anu,

It definitely depends on the format of the comments.

With Regular Expressions, you looking at seeing if you can put together a pattern that could match the data you need.

eg.  if the text looked like this

Approver: domainusername

You could put together an expression like:

w+\w+

Or maybe:

Approver: w+\w+

Or even:

(?<=Approver:)w+\w+(?= )

It all depends on what you're seeing.

cheers,

Vadim

Userlevel 7
Badge +17

It also depends on whether they use Lazy Approval to respond. We can definitely help you for a regular expression pattern, you will find many examples of them throughout the site.

Other things you can use beyond matching strings in a response are references within the workflow

  • Last Task Respondent Display Name
  • Last Task Respondent - returns login
  • All Approver Comments

If you are using a Flexi-Task you can determine the outcome using the Store Outcome In option and put into a variable or by knowing which branch you are in after the response. You can also use the reference Current Time and Current Date in the branches following the outcome of the task to determine the timing. It will be relatively close to the true response. Using these features could be easier than finding the text from a comment for from an email response because of the variations and possible omissions within the responses.

Userlevel 7
Badge +17

If you are trying to pull this from the All Approver Comments, Vadim has a good example. But if it needs more tuning, let us know your input string and results from testing. Any details will help to find a perfect match!

Userlevel 7
Badge +17

Here are many other examples of using Regular Expressions on Approver Comments Remove approver comments

Badge +7

You can try your regular expression online.  Ther are various sites that offer sucha service.  I prefer Online .NET Regular Expression Tester and Reference,​ because it is. Net based.

Badge +3

the input text is like this: Lastname1, Firstname1 (Not Required) 1/7/2016 2:02 PM - Lastname2, Firstname2 (Not Required) 1/7/2016 2:02 PM - Lastname3, Firstname3 (Not Required) 1/7/2016 2:02 PM - Singh, Anu (Approve) 1/7/2016 2:02 PM - 1/7/2016 2:02 PM (Singh, Anu) test From this I need the Name of the person who approved and date and comment. So in the case, I should be able to output Singh, Anu - 1/7/2016 2:02 PM Comment: test.

Userlevel 7
Badge +11

Hi Anu,

This should get you started, but be aware that there are many ways to do the same thing with Regular Expression, and by no means proclaim that this expression is the best way:

[w]+, [w]+ (Approve) d{1,2}/d{1,2}/d{4} d{1,2}:d{1,2} w{2}

That should get you :

Singh, Anu (Approve) 1/7/2016 2:02 PM

You can extend this to get the other bits that you want.

Vadim

Userlevel 7
Badge +17

This seems to work Anu. I also recommend using the Run Now feature for pre-publish testing. Simply put in the text you supplied here as the input, then add the pattern and run it. If it is coming out well, then do a live test in a workflow for final QA.

Userlevel 5
Badge +14

I find it myself the most reliable and convenient way to read approver's outcomes/comments directly from workflow task list.

in the flexi task you can store all the tasks IDs to a collection and afterwards iterate through the collection and read any info you need from task list for every single task.

I too fought with regexes to pick the response of interest in the past but wasn't able to find any reliable template.

note that if you allow users to type in any free text they may (accidentally) enter a pattern that you rely in your regex on and your output will very likely be senseless.

Userlevel 7
Badge +17

Anu Singh​, were we able to provide you an answer you were looking for?

Badge +3

thanks for this regular expression help.  can you please give me a modified version of this regular expression so that it extracts the second date, not the first one.

Userlevel 7
Badge +17

If you need Singh, Anu (Approve) 1/7/2016 2:02 PM - 1/7/2016 2:02 PM you may be able to

[w]+, [w]+ (Approve) d{1,2}/d{1,2}/d{4} d{1,2}:d{1,2} w{2} - d{1,2}/d{1,2}/d{4} d{1,2}:d{1,2} w{2}

Badge +3

Hi Andrew,

I only want the second date not the first date.

How do I do that?

Thanks,

Anu

Userlevel 7
Badge +17

I think you will have to do this in two steps.

  1. Match the string with the dates you want
  2. In a second RegEx action, Extract the match of the first date that is followed by a -
Badge +3

Sorry, I’m not too familiar with regular expressions. Could you please help me with the extract regular expression as well?

Userlevel 7
Badge +17


Simply use d{1,2}/d{1,2}/d{4} d{1,2}:d{1,2} w{2} - to remove the first date by using the regular expression action with the Replace Text option (not the extract as I mentioned before). Replace the matched text with a blank value in the Replace Text box. Then store the result in another or the same variable.

Userlevel 7
Badge +17

And make sure you include the trailing dash as I typed it, otherwise you could match both dates.

Badge +3

Thanks Andrew.

Anu

Userlevel 7
Badge +17

No problem! You have a lot of responses here from intrigued helpers (great work community!), let us know Anu Singh​ if your question has been answered.

Badge +3

You can use Following Pattern

(?s:^.*?({WorkflowVariable:varApproverName})(.*))

Opertaion is: Replace text

Replacement text: $1

Input text: Approver Comments (i.e is present in Common)

If Approver Comments not required

then you can use

Pattern

(?s:^(.*)s(.*?),s(.*?)(NotsRequired)(.*))

Repalce text

$1

Approver comments

Badge +3

Hi Andrew,

Is there any way to modify this regular expression to ignore the spaces or “-“ in people’s names?

Thanks,

Anu

Userlevel 7
Badge +17

possibly, but you could over complicate the expression as the match needs to have a certain order or sequence. Instead, if you need to remove some extra data, you could do a string manipulation after the reg ex match using a substring function.

Reply