cancel
Showing results for 
Search instead for 
Did you mean: 

Regular Expressions in Nintex Workflow

Nintex Employee
Nintex Employee
39 54 79K

The Regular Expression action is an extremely powerful action for splitting text, replacing text or getting data out of text.  Don't be worried about not knowing how to put Regular Expressions together.  There are a number of sites online that give you the basics of it.  In this post, I'll give you some quick tips on how to get data that you may need.

Splitting Text


There are times where you will be getting data from lists, from web services, databases or elsewhere, where the data comes to you in a delimited form.  Either comma delimited, as in CSV files, or semi-colon delimited, as from some accounting systems or some other delimiter.  If you need to get the data into a Nintex Workflow collection variable, you can use the Regular Expression action to split the data based on that delimiter.

Split.png

Notice that the first data entry field to fill is in the pattern.  When doing a split, this is the delimiter.  The character or characters that will be used to split a piece of text.  The operation is "Split" and the Input text, I've simply typed in some text with the comma separating them.

The result of this needs to be stored in a Nintex Workflow collection variable.  For more information on the collection variable, take a look at these :

http://nintexdownload.com/Nsupport/tutorials/How%20to%20use%20the%20Collection%20variable.pdf

and

Nintex Workflow - Collection Variable - Vadim Tabakman

The interesting thing to note here, is that the pattern is a Regular Expression.  Although it could be a single character, like a comma or even several characters like #!# if that is the delimiter (I used to use that), it could also be very intelligent as you could give it options.

eg.  ;|,

The above example is stating that the delimiter could be a comma or a semi-colon.  That really opens things up doesn't it?

To get a little more elaborate, what if your delimiter was a period (dot or full stop for non US people)?  Well, in Regular Expressions, a period is a special character.  So in that case, you need to escape it.  You would do it like this:

\.

Putting the backslash on it escapes it and lets the Regular Expression parser recognize that you want to deal with a period and not their special meaning of it.

Replacing Text

Using a Regular Expression action is not the only way in Nintex Workflow to replace text.  There is an inline function you can use in a Build String action, called fn-Replace.  Having said that, that action only lets you replace a known piece of text with another piece of text.

The Regular Expression action allows you to build complex expressions so that not only do you replace a piece of text, but you can find any number of matching sequences of text or replace only one piece or just from the beginning or from the end.  The number of expressions you can build is almost infinite.

Replace.png

In the screenshot above, we have some text "abc-def-ghi-123-lmn" and we cant to replace the numbers with a ###.  Now if you were to use this with a Build String action (with fn-Replace), you would need to know those 3 digits.  But if this was data coming in from another system, those 3 digits would be different each time.  That's where the Regular Expression action is so powerful.

You can build an expression like [0-9]+.  This is saying that every in my text where I find one or more digits, I want to replace them with ###.

Another expression that would do the same thing is [\d]+ .  The reason I show you this, is because there may be other expressions that do the same things as what you're doing now.  Some will make your expression smaller and more streamlined.  Others maybe actually be faster at finding the text you need.  Although I would say that for workflows that you build, you're unlikely to come up with a scenario that the performance of a Regular Expression is something to worry about.

Extract Text

This can be as simple as the replace above, or something more complete.

To extract the numbers from the example above "abc-def-ghi-123-lmn", you can use the same expression.

[\d]+

The main thing to note here, is that the Extract option will only save the results into a Collection variable, even if you know you're only getting one result back.  So you should be aware of this when extracting data.

ExtractSimple.png

Where it gets a little more complex, is if you want to extract data between two strings.

Let's take the above text as an example.  If we needed to get all the numbers, but they had to be between 3 text characters and the dash, on both sides, how would this be done?

In this case, our Regular Expression gets a lot more complex.  It would look like this :

(?<=\w+-)\d+(?=-\w+)

You're probably looking at this and thinking it is gibberish.  That's what I thought it was when I first was learning about Regular Expressions.

It broken up into three components.

(?<=\w+-) - This is called a Positive Lookbehind .  We're looking for some text that is a number of text characters followed by a dash (hypen).

\d+ - This is the data we want to extract.  It is one or more numerical digits.

(?=-\w+) - This is called a Positive Lookahead.  We are looking ahead to find a dash (hypen) followed by one or more text characters.

ExtractComplex.png

Although when you look at complex regular expressions, they look daunting, they actually aren't.  You just need to spend a little time playing around with them and maybe running through some tutorials and you'll be well on your way to build awesome business solutions.

Match

The match operation, I'm not going to talk about much, since it's similar to the others. It simply lets you know if based on your Regular Expression, there is a match in your text.  A good example of this, is if you didn't have Form validation and you wanted to validate that someone had entered a valid email into an item field that the workflow is running on, you could use this functionality to match it.  If it matched, you could continue with the workflow but if it didn't, you could notify the initiator to get them to fix the issue.

Conclusion

Regular Expressions are extremely useful in countless scenarios.  Don't be afraid to play around with them and use them to make your workflows very slick.  If you want to learn more, take a look at this site, which is one that I go to often to if I need a refresher - RegExr: Learn, Build, & Test RegEx

I hope this explains a little on how to use Regular Expressions in your Nintex Workflows.  If you have any questions, please free to post them in the comments section.

54 Comments
Nintex Newbie

OK, very good documentation but how can I retrieve the right portion of this string ?

The Delimiter is a (space - space) for example:

Component 1 - Component b

I want to store the phrase 'Component b'  in the above string into a new Variable (Column)

Idea is to use a regular expression ?

Nintex Employee
Nintex Employee

Hi Jaap,

there are probably a number of different expressions you can use, but this one should work for you:

[a-zA-Z\d][a-zA-Z\d ]+$

cheers,

Vadim

Nintex Newbie

Excellent article Vadim!  I can always use a refresher on regex.  Thanks for taking the time to write and post it!

Nintex Newbie

Hi,

I'm trying to split a string delimited by semicolon. I used the below pattern (;) with a space and without it also. The input text is value from a lookup column. During the execution of the workflow I logged the output of the collection variable which returned only (;) as output. Please let me know what can be the issue. PFB the screenshots for reference.

Regex.png

history.png

Nintex Employee
Nintex Employee

Hi Shyam,

when you log a Collection variable, it will automatically log it's contents in a semi-colon delimited fashion.

The best thing to do, is to use a Collection operation action to do a "Count". Then log the count variable.  It will give you an idea of how many items are in the collection.

Hope this helps.

Cheers,

Vadim

Nintex Newbie

Thanks Vadim Tabakman

Will try what you have suggested.

Regards,

Shyam

Not applicable

Just for the record I needed the same thing, but in case there were more than one hyphen I had to make sure I got the text at the end after the last " - ".

After reading a few blog posts on the topic, I used the following regular expression as the pattern to extract the text and it worked perfectly:

(?<=\w+\s-\s)\w+

Hope this helps someone.

Nintex Employee
Nintex Employee

Thanks for sharing the Stephen.  Definitely a useful expression to have.

Not applicable

thank you very much for this overview!

I have a question though, and I don't know enough about regular expressions to see if they can help. I have to create a survey request where a user can fill in a field (people lookup) with multiple entries (more than 1 person, but not always the same number of people), and then a workflow should create as many new items in a list as there are people in the people lookup field. So, they can enter emails separated by a semicolon (;) - but I can't figure out how to calculate how many people they have entered.... is there a way to count the semicolons? or count the number of "@", or something?

any help would be appreciated, thank you

Nintex Newbie

Would it be possible to capture the users in a collection variable (send the email to the collection var) and use the collection action to count the amount of values in the collection?

Sent from my Windows Phone

Not applicable

thanks for your insight. it could be a solution, but sounds like something that is outside of my level of knowledge and experience. i'll look into "collection variable" and "collection action", since this is the 1st i've heard of this

Nintex Newbie

It would be easier than reg ex

Think of the collection variable as an array. Where you can store multiple values where they are separated by ; so for example if you multiple user names, they would be stored as domain\user1;domain\user2;domain\user3 etc..

Now you can use this variable type as a recipient for purposes of send emails/tasks etc. If you use the action search at the top of the action panel on the left hand side, type 'collection' grab the collection action and in the config there are a number of options.. This is where you can get values out of the collection, put new ones in, and also count how many values are in there.. Check out these links that a bit of info around collections

https://community.nintex.com/docs/DOC-1349

http://www.vadimtabakman.com/nintex-workflow-collection-variable.aspx

http://www.sharepointpub.com/formatting-a-table-from-collection-variables-nintex-workflow/

Sent from my Windows Phone

Not applicable

thank you so much for this information, and the links.

In the time since your 1st reply I have also found:

http://nintexdownload.com/Nsupport/tutorials/How%20to%20use%20the%20Collection%20variable.pdf

and have been reading just to get more info on how these functions work. I'll take a look at your links tomorrow (23:38 here in the CET timezone). Again, thank you so much for your info

Not applicable

Often you have a list field that holds multiple values (e.g. people’s names), but you need to process each value individually in sequence. Here is how.

These notes were written for Nintex Workflow 2007, but the steps should be same for any version. The basic idea is to split your multi-valued field (e.g. people’s names) into a set of values within a collection variable. This lets you loop through each value individually. You also need to handle the special case when the field is empty, because (in Nintex W/F 2007) the loop will also try to process that.

Here are the steps to set this structure up, using as an example a field that can hold multiple names (and it can also be empty).

1. Create 2 or 3 Nintex loop variables in Settings > Workflow Variables.
a. Add a collection variable to hold the values
b. Add a variable to hold a single instance of a value
c. Optionally, add a number as an “index” to indicate your position in the collection.

2. Start by adding a "Regular Expression" workflow step to copy your field to your collection.
a. Set the method as "Split".
b. The Pattern is a single semicolon – “;” without the quotes.
c. Use the Insert Reference button to select your multi-value field as the Input text.
d. Store result in your collection variable

3. After the "Regular Expression" add a "For Each" loop to process your values individually
a. The "Target Collection" is your collection variable
b. "Store result in" is the variable that holds a single instance of a value
c. Index is optional. It is for the numeric variable to be used as a count.
Note: The index starts counting from zero – so the first value will be number 0.

4. Inside the loop, add a "Run If" statement to prevent processing an empty collection. That is because the Regular Expression split function adds a blank entry into the collection variable even when there is no input value. Set up the "Run If" to test if your variable that holds the single instance of the value is not empty.

5. Inside the "Run If" statement add your logic that you need to process each value in turn. Use the workflow variable that holds the single instance of each value. This is where you could create a list item or email the individual user, etc., as required.

Nintex Newbie

Hello,

I made a list workflow with this pattern:

^{WorkflowVariable:varDisplayName}.*({WorkflowVariable:varDisplayName}\))

This works fine in one site.

But I Need this within the MS Project Site. I tried this pattern in a Nintex-Project workflow and without the Project part as site Workflow.

But here this pattern changes nothing.

How can it be, That the same Regular Expression works in one site and not in an other site?

There is no error. I logged all variables in the history.

If I open the regular Expression and choose RUN, I can copy the text from the history and it works.

I only Need the comments from Flexi-Task without Username and date/time inside.

I use the same Thing on a list, and it works.

Would be very happy, if someone can tell me, why the same Expression doesn't do the same in different sites.

Thanks a lot from Swiss

Dagmar

Nintex Employee
Nintex Employee

Hi Dagmar,

when you log the varDisplayName variable, what is it's value?

Maybe someone can try to reproduce this here.

cheers,

vadim

Nintex Newbie

Hi Vadim

Thanks for your reply.

First I tried to do it in a big workflow. There it doesn't work.

Then I write the Variables into a new created SharePoint List.

I have one single line text and one multiline text list elements.

I build a site workflow (in the MS Project Server SharePoint site)

With this Actions:

Read this two fields into variables (and write to WF history)

And do the replacement

Write in a third field in the list. (and write to WF history)

(This works in a site workflow in a different SharePoint site (Without Project)

Comment In =    Volkmann Dagmar (Approve) 12.12.2014 11:35 - 12.12.2014 11:35 (Volkmann Dagmar) Test4 Test4 Test4 - Test 4

Display Name =    Volkmann Dagmar

And I want   =    Test4 Test4 Test4 - Test 4

When I simulate the Replacement it works fine. I tried to copy the fields from the list and I tried to copy the data from the workflow history. Always fine when I simulate it.

If the WF runs, the Input and the Output are the same, but the data in the history Looks fine.

Thanks a lot

Dagmar

Nintex Employee
Nintex Employee

Hi Dagmar,

sounds like something really weird is going on. I'd suggest you reach out to our support team for this issue, is it's not behaving the expected way in different sites.

cheers,

vadim

Nintex Newbie

Hey Vadim

I was experimenting with the regular Expression. I need an Expression to verify that the Input has to be a number >0 but the Input can not be "empty". The Expression: ^.+$ for "not empty" didn't work. The Field I apply the Expression the following

May you or someone from the community has an idea?

Thanks in advance

Michelle

Not applicable

Thanks for the write-up. I am having an issue with a simple text search/replacement. I want to remove the following characters from a multi-line text string: , ' " . I am using the expression ("(,|')). When I do a run now it works just fine. See the picture below. When I run the workflow on a SharePoint list it removes the , and ' but it leaves the " alone. Any ideas as to why?

runnow.png

Nintex Employee
Nintex Employee

Hi Lawrence,

I'm not sure why it works in the Run Now but not when the action runs.

Try escaping the double quotation mark.

eg. (\"(,|')).

cheers,

Vadim

Not applicable

Thanks for the response, Vadim. I tried escaping, as you mentioned, and that still doesn't solve the problem. Perhaps I need to put in a support ticket.

Nintex Employee
Nintex Employee

Hi Lawrence,

I think that's a good idea.  I hope you contact Nintex Support and got to the bottom of your issue.

Cheers,

Vadim

Nintex Newbie

Vadim Tabakman​ Great post! I was using a couple of list lookups in my nintex form for user id request that cascades, giving the approver for the department selected. Both values were saved back to list as single line of text. Both of them also had ID's and special characters appended to them. I followed the Regexr site and was able to get the actual department name and assisgn person field based on the regexr stripped approver text field.   Works really well! Thanks.

Image

Not applicable

Hi,

I am planning to extract b c d from the below input text (without the strings and store it in a variable)

a:b:c:d:e

Can you please help me with this? Tried different ways, but couldnt get the desired result.

Nintex Employee
Nintex Employee

H Baradwaj,

you need to configure the Regular expression to do a "Split".

Then for the expression, just put in the :  

Store the result in a Collection variable.

cheers,

Vadim

Nintex Employee
Nintex Employee

Or you could configure it to do an "Extract" and for the expression have a \w

also store the result in a collection variable.

cheers,

Vadim

Not applicable

Sorry Vadim, I am lost. What do I put in the regular expression? Is it

-> :

or

: ->

Nintex Employee
Nintex Employee

Sorry.. just the colon by itself.

:

Not applicable

DO you mind giving me the exact expression I need to use?

Also, once I store the data into a collection variable, I must use Index, right? And the indexes shd go star from 0?

Not applicable

I tried that, however I couldn't extract the data from collection variable, I struggled to do so.

Nintex Employee
Nintex Employee

If you use an Extract operation in the Regular Expression the expression would be

\w

You can then use a For Each action to go through each value in the collection, or if you want to get value at a specific position, then use the Collection Operation to do a "Get" and yes, the index starts at zero.

cheers,

Vadim

Nintex Employee
Nintex Employee

are you sure your data is

a:b:c:d:e

??

The expression needs to change according to the input text you have.

\w means a single character.  So if you have something like acsd:fd:werwe:fsdfds, then the \w expression won't be enough.

If you have numbers in it, that expression won't work either.

After you run the Regular Expression action, use a Log in the History List action to log the Collection variable.

What is logged to the workflow history?

cheers,

Vadim

Not applicable

Hi Vadim

Thanks a million for your prompt reply, a:b:c:d:e is just an example, but in reality, it can be anything.

Just wanted to extract the content between first : and fourth :

Thats my actual requirement.

Nintex Employee
Nintex Employee

Then you'll need to figure out what data can be between each colon, because your expression will need to handle that.

eg.

\w will get a single alpha characters

\w+ will get one or more alpha characters

\d will get a single digit

\d+ will get 1 or more digits

\d* will get 0 or more digits

[\w\d]+ will get 1 or more alpha or digits in a group

Check out the Cheatsheet here: RegExr: Learn, Build, & Test RegEx

Not applicable

But can you suggest me how to extract all the text considering : as the delimiter? I tried both Split and Extract putting : as delimited and then tried getting values from Collection Variable using For Each, it doesnt work.

Nintex Employee
Nintex Employee

The problem is, I don't know what characters you could have between the colons to build up a proper expression.

But I would start with doing a Regular Expression configured to do a Split

The expression would be

:

This should split your data by the colon delimiter.  If this isn't working, can you create a simple workflow to demonstrate it and share it here?

Not applicable

Hi all, thanks for the valuable inputs. However I'm facing some issue with extracting info. My column contains Follow Up=10;Meeting=90;Research=20;Transferred=70; so how do I get the value 10 from only Follow Up​. Any suggestions?

Nintex Newbie

Well, use the prefix literal in the expression and use 'digit' class with unspecified number of digits in a capturing group. Like this:

Follow Up=(\d+) or Follow Up=(\d?)

Nintex Newbie

Hi Vadim Tabakman

I am displaying rich text content in mail using email notification action. The content is coming from multiple line of text column.

This content has SharePoint page link. When I open this link from email, it wont open as hyperlink will be set as relative link in

multiple line of text column always.

ie /sites/test/Pages/Home.aspx instead of full url.

How can we fix this using Nintex workflow action. Is tehre any way to fix using regular expressions?

Thanks,

Prashant

Nintex Newbie

Hey Vadim Tabakman

I'm totally new to regular expressions. I'm trying to extract all the data (alpha and numeric) between an open and close bracket. [ ]

I'm sure it's super easy...

Thanks

Kassie

Nintex Newbie

Never mind, I figured it out.

\[(.*?)\]

Nintex Employee
Nintex Employee

Hi Kassy,

Configured the Regular Expression to do an Extract.

Pattern--->   (?<=\[)[\d\w]+(?=\])

Store the result in a Collection variable.

Then you'll need a Collection operation action and configure it to either do a Get at the zero position (that's the first position in the collection)

Or, even easier, configure the Collection Operation to do a Pop, if you expect to only have one result.

cheers,

Vadim

Nintex Employee
Nintex Employee

ooh that's way nicer!!!

Great stuff and thanks for sharing Kassie.

Vadim

Nintex Newbie

Hey thanks for responding Vadim!

Now that I've grabbed the string, I'm wondering how to remove all the quotes "" from it. Do you know a regex for that? I've been goggling like mad but no luck so far with a successful regex.

Thanks

Kassie

Nintex Employee
Nintex Employee

Hi Kassie,

you could just try a \" and configure it todo a replace.

Or another way would be to use a Build String action and use the fn-Replace function.

Good luck with it.

cheers,

Vadim

Nintex Newbie

I was doing an extract regex rather than a replace. Then, I was replacing with " "... that didn't work out.

I ended up leaving the replace field empty and that worked.

Thanks again for your help Vadim!

Kassie

Nintex Newbie

Hello Vadim Tabakman,

I need some help, I have this comment from after Assign Flexi task

"Name Surname (Approve) 8.8.2016. 11:11 - 8.8.2016. 11:11 (Name Surname)  some comment Name2 Surename2 (Approve) 8.8.2016. 11:11 - 8.8.2016. 11:15 (Name2 Surename2) some comment Name3 Surename3 (Not Required) 8.8.2016. 11:11 -"

I want to get all Names Surnames of people who approved this task, Name and Surname before (Approve). How to do it? Please for your help.

Thanks !

Nintex Newbie

Hi Vadim

I have used people or group function in the form and I want to show the detailed in the email body. I have managed to grab most information however i am unable get clean information from people or group field. For example I have field  for Reporting manager and the out put shows as - i:0#.f|membership |theek.@live.com|. I want to display the name and it showing the email with the claim token.

i am using Nintex 2013.

I have try to use Regular Expression but the result is same.

Thanks

Theekshana  

Nintex Employee
Nintex Employee

Maybe you can use the Query LDAP or Query User Profile action to take that and get back the display name.

Vadim