Vadim Tabakman

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

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+(?=,)

If you have text that you need that has spaces in it, then try this:

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

If you are using Nintex Workflow Cloud, then the expression looks a little different, as NWC utilizes the Ruby Regular Expression syntax.

CN=([^,]*),

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 had an idea to reduce this to 1 action.  This will be something I will write about in a future post.If I get it to work, I'll post another article on it.  At this stage, I haven't done this.

Downloads

Nintex Workflow 2013

Download the Workflow - Download and import it into the Workflow Designer Page

Posted by Vadim Tabakman Saturday, May 12, 2012 9:22:00 AM Categories: Collection Operation Collection Variable Nintex Workflow Regular Expression
Copyright Vadim Tabakman
Rate this Content 2 Votes

Comments

Friday, September 14, 2012 6:57:02 AM
Sam

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

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.
Friday, September 14, 2012 8:17:10 AM

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

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? 

Friday, September 14, 2012 9:34:54 AM
Sam

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

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.
Friday, September 14, 2012 11:42:21 AM

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

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

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

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

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 |())

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

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

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

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

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

Nice, very useful, thanks!Cool

Tuesday, August 27, 2013 9:33:55 AM
Bob Eldredge

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

ANOTHER EXCELLENT POST VADIM!

Tuesday, August 27, 2013 9:36:05 AM

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

Wow thanks Bob.  Glad you liked it :)

Wednesday, August 28, 2013 5:53:16 PM
Myriam

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

Just what I was looking for.  Thanks Vadim!

Thursday, August 29, 2013 3:30:24 PM

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

Great to hear Myriam :)

Friday, October 11, 2013 1:35:45 PM
Janice

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

I created the workflow as you directed, and then tested with 1 item in my library.  The workflow errored giving me the following message:

Error:  Index property is greater than the number of items in the collection.  My index property is default at 0.  I do not have the option of leaving the Index field blank.

My text string is:     AS2000-123 - test descriptive text.docx   (basically this is a file name)  I want to extract 'test descriptive text' without all the stuff before it, or the .docx after it.

I used the pattern  (?<= - )\w+(?=.docx)   which I thought would match and remove the space/dash/space immediately before the description, and also remove the .docx at the end.

Am I missing something?

Thanks!

 

Wednesday, May 28, 2014 2:56:13 AM
Suyog
Gravatar

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

Thanks dude, this has saved my job.  Excellent

Wednesday, May 28, 2014 7:48:07 AM

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

Hi Suyog,

glad to hear it :)

cheers,

Vadim

Wednesday, June 11, 2014 7:44:00 PM
Fernando Hunth
Gravatar

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

Great!

It worked for me

Wednesday, June 11, 2014 10:10:38 PM

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

Hey Fernando,

glad this helped :).

cheers,

Vadim

Thursday, May 21, 2015 3:54:36 PM
Derek
Gravatar

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

 HI, I would appreciate some help with a regex for string extraction fro use in Nintex, and have no joy in sucess.

The string is per this example !]1234567,2345678,45678,8765678[]

the extract i want is after the !] and before the []

From the extract I will split on the comma to give me a collection of numbers.

Thanks

Derek

Thursday, May 21, 2015 4:10:38 PM

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

Hi Derek,

if you just want the numbers, set the RegEx action to Extract and your pattern to this:

\d+

Store the results in a collection variable.

cheers,

Vadim

Thursday, May 21, 2015 4:16:37 PM

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

Hi Derek,

if you want to do the bit between those brackets, try this expression:

(?<=!])[\d,]+(?=\[\])

cheers,

Vadim

Wednesday, August 5, 2015 2:08:29 PM
Diane Santini
Gravatar

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

We have a lot of smartsheet users who don't want to use Sharepoint.  Is this something that would be used to convert their data?

Thursday, August 6, 2015 9:22:22 AM

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

Hi Diane,

I don't know enough about SmartSheet to know if they support Regular Expressions.  But if it does, then you could definitely use this to extract data from one place into another.

cheers,

Vadim

Monday, August 24, 2015 10:38:11 AM
A
Gravatar

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

Vadim,

     I am trying to use this to pull an ID Number from a document name, but its pulling an error. I came across your blog in research to find a fix maybe you can help? I was using (?<=_=)/w+(?=.) to pull the number ie. TestDoc112.docx or  TestDoc112.pdf.

The error is saying that the index property is greater than the number of items in the collection.

Monday, August 24, 2015 12:23:42 PM

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

Hi A,

why not just try something like :

\d+

but if you want more elaborate:

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

cheers,

Vadim

Monday, August 31, 2015 12:35:21 PM
Juli
Gravatar

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

So in looking at your example I *should* be able to take this:  Reid, Juli and using this (?=,) extract just the text before the ','

Monday, August 31, 2015 11:55:58 PM

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

Don't know if that will work. I've never used this technique to do what you're doing.

cheers,

Vadim

Friday, September 11, 2015 5:09:38 PM
A
Gravatar

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

So.... now my client wants the file name to end in numbers and symbols

Ex Document Name 15-001-111.doc, Document Name_15-001-112.pdf

 

How can I extract "15-001-111" ?

Friday, September 11, 2015 5:45:38 PM
A
Gravatar

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

Preferably Just pulling the Numbers 15001111, 15001112

Saturday, September 12, 2015 8:39:16 AM

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

Hi A,

to just get the numbers from a filename try:

\d+

cheers,

Vadim

Friday, May 6, 2016 6:36:16 AM
Ellen Farley
Gravatar

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

I need to convert an email address in firstname.lastname@URL format to lastname, firstname format.  Would I be able to do this with regular expression(s)?

Wednesday, February 8, 2017 2:47:44 PM

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

Hi, Vadim.

This is EXACTLY what I am looking for. I am encountering the identical issue with the LDAP query and my data returns in the identical format as your example. However, when I pass the contents of my text variable through the regular expression, the collection does not populate. When I manually run my regular expression, it tells me the command executed successfully. So why doesn't it populate my collection variable with the data? I even tried hard coding the regular expression with the results of the LDAP query instead of letting it populate from the text variable with the same result. Manually running the regular expression says the command executed successfully, but running it through the workflow does not populate the collection variable.

Wednesday, February 8, 2017 11:20:56 PM

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

Can you provide examples of the data and your regular expression?

Thursday, February 9, 2017 10:34:34 AM

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

The Regular Expression I copied right out of your blog: (?<=CN=)\w+(?=,)

These were the results I was getting:

EID Text: A1122334
Manager Text: CN=John Doe,OU=Users,OU=DAT-Group1,DC=COMPANY,DC=PVT
Manager Coll: (nothing)

Then I started splitting the data and got these results:

EID Text: E1122334
Manager Text: CN=John Doe,OU=Users,OU=DAT-Group1,DC=COMPANY,DC=PVT
Manager Coll: CN=John Doe;OU=Users;OU=DAT-Group1;DC=COMPANY;DC=PVT

The only way I could get a result with the extract method using (?<=CN=)\w+(?=,) in the Regular Expression was after I split the data at the comma. However, for some users I would get CN=John Doe and for other users I would still get the whole string of data.

I have figured it out using part of your process. I perform the LDAP query and get the contents in the Manager Text variable, use a Regular Expression to split the contents of the Manager Text variable at the comma and get the contents in the Manager Coll, use a Collection Operation to get the first value of CN=John Doe, use another Regular Expression to replace the CN=, and I end up with "John Doe".

I'm hopeful this will work consistently each time. I have tested it with three different profiles which were returning different results and are now returning the same result.

I'm not sure why I need to jump through these hoops, but this is the only way I could get a consistent result. The only difference I noted is that John Doe is in a different group from the other users, which may have more security around it. (The data returned in the OU=DAT-Group1 part of the string.)

I would appreciate your thoughts on the workaround I came up with.

Thursday, February 9, 2017 11:08:16 AM

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

Hi Hapchetsut,

 

I think it's the Space in between John and Doe that's causing it.

Try this:

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

 

Vadim

Friday, February 10, 2017 7:41:19 AM

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

That didn't work either. When I manually execute the Regular Expression , it is successful. In the workflow, it isn't. frown

Friday, February 10, 2017 8:09:14 AM

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

Here's my workflow that worked for me : http://vadimtabakman.com/Data/Sites/1/media/Blog/textbetween/text_between_workflow.nwf

You must sign in to this site to post comments.
Already Registered?
Sign In
Not Yet Registered?
Register

Statistics

  • Entries (279)
  • Comments (1769)

Categories