Nintex

Nintex Connect

SkySync
BlueStripe
BlueStripe

Training - Combined Knowledge

Training - TekDog Inc

Nintex Workflow - Regular Expression - Extract text from between two text strings

  • RSS
  • Add To My MSN
  • Add To Windows Live
  • Add To My Yahoo
  • Add To Google

Statistics

  • Entries (119)
  • Comments (310)
Posted by Vadim Tabakman Saturday, May 12, 2012 9:22:00 AM Categories: Collection Operation Collection Variable Nintex Workflow Regular Expression

Download

Download the Workflow : Click here to download

Note: This workflow was built in Nintex Workflow 2.3.3.0.  If you are running an earlier build, it may not import.

Introduction

After using the Nintex Workflow Query LDAP action to retrieve some information, I ended up getting it in a distinguished name format:

CN=wombat,OU=Users,OU=US,OU=Support,DC=alphas,DC=vadimtabakman,DC=com

I needed to pull out the CN value.  It's possible to do this with an Inline Function call like fn-SubString, but in order for that to work, you need to know exactly how long the substring is and it's position in the input string.  Since the CN value can be any length, that would not work.

So the solution is to use a Regular Expression action, configured for an Extract.

The Regular Expression looks a little ugly, but it does what I need.

(?<=CN=)\w+(?=,)

Explanation

(?<=CN=) - Positive lookbehind. Matches the "CN=" before your main expression without including it in the result.

\w+ - Matches 1 or more of any word character (alphanumeric & underscore)

(?=,) - Positive lookahead. Matches a "," comma after your main expression without including it in the result.

This results in text between a CN= and a comma without include those bits of text.

Usage

This workflow is quite simple (3 actions).  So I won't go into a great deal of detail.  The screenshots should suffice.

Workflow looks like this :

 

We will need 3 variables.

Collection variable : to store the results of the regular expression extract.

Number variable : to keep the index 0 as the first index into the collection variable

Text variable : to then get the first value from the collection and store it here.

Next we add the Regular Expression action.  I've typed in my input text, but if you use something like this, you'll have the input text in a variable or item field.

The results are in a collection variable.  It's possible with an Extract that you will get more than one result. eg. if instead of CN= you used DC=, you'd get 2 results.

Now we need to get the first result from the collection and store it in a text variable.

Finally, I want to update my Title field for my current item, with the CN value that I extracted.

That's it.  It doesn't really need more explanation than that.

This can be used to extract text from between any text strings, not just from a Distinguished Name.  Hopefully, this helps some people who has this requirement, as I've had in the past.

Conclusion

I always look for a way to make my workflows smaller.  Although a 3 action workflow is not exactly huge, when you start using this throughout a workflow, your workflow can grow quite quickly.

I have an idea to reduce this to 1 action.  This will be something I will write about in a future post.

Copyright Vadim Tabakman

re: Nintex Workflow - Regular Expression - Extract text from between two text strings

Tuesday, December 04, 2012 9:19:40 AM Lehus

Nice, very useful, thanks!Cool

re: Nintex Workflow - Regular Expression - Extract text from between two text strings

Wednesday, November 14, 2012 9:52:10 AM

Hi Lehus,

I made a desktop app that I use often : http://vadimtabakman.com/regex-tester.aspx

I also use this site a lot: http://gskinner.com/RegExr/ as it has examples of the symbols you can use on the right of that page.

For LDAP, I don't have a site on me, but I'd search online for LDAP tutorial.

cheers,

Vadim

re: Nintex Workflow - Regular Expression - Extract text from between two text strings

Wednesday, November 14, 2012 8:48:42 AM Lehus

Hello! Vadim, could you please help me? Where i can find a full list of these symbols for regular expressions? (like: (?<=))

Can i use these for Replace expression? For example i have text "ABCD123\456EFG" and i want to replace ALL ANY text BEFORE "\" by another (in this example i want to get "456EFG" only replacing by none)

Also, where i can find an explanations for symbols in LDAP query? (like: &() or |())

re: Nintex Workflow - Regular Expression - Extract text from between two text strings

Friday, September 14, 2012 11:42:21 AM

Hi Sam,

I've removed the rating part and I'll take a look at the Captcha part.  I've never had a problem with it. 

cheers,

Vadim

re: Nintex Workflow - Regular Expression - Extract text from between two text strings

Friday, September 14, 2012 9:34:54 AM Sam
I'm using IE there's a box that says "Rate this Content", "Give feedback on this content" on the top right. And captcha for me always fails the first time, I almost have to refresh first in order to write the feedback.

re: Nintex Workflow - Regular Expression - Extract text from between two text strings

Friday, September 14, 2012 8:17:10 AM

Hi Sam,

I don't see the Feedback box in the middle.  What browser are you using?  Can you send me a screenshot of what you are seeing?

What's wrong with the Captcha? 

re: Nintex Workflow - Regular Expression - Extract text from between two text strings

Friday, September 14, 2012 6:57:02 AM Sam
Your feedback box sucks, it's right in the middle of the content and there's no way to "X" it so it goes away. Clicking on "No Thanks" is forcing me to write a comment. Oh, and your captcha doesn't work right either.