cancel
Showing results for 
Search instead for 
Did you mean: 
kevyn_williams
Nintex Newbie

Regex extract producing extra characters in the results [" "]

Jump to solution

Hi there,

I'm using a regex in a workflow to extract some text from a string, save it to a variable and then update a column with that variable (if it doesn't already match).

My regex:

(?<=-).+(?=-)

However when the column is updated, the value entered has [" "] around it - does anyone know why?

Original string:

RANDOMSTRING1 - RANDOMSTRING2 - RANDOMSTRING3

Regex (extract):

(?<=-).+(?=-)

Result:

[" RANDOMSTRING2 "] 

Any help greatly appreciated, example here: regex101

Labels: (2)
Reply
8 Replies
paul_crawford
Nintex Newbie

Re: Regex extract producing extra characters in the results [" "]

Jump to solution

Hi Kevyn Williams

Try this

(?<=- ).+(?= -)

Notice the space after the first hyphen and before the second hyphen

Hope this helps

0 Kudos
Reply
paul_crawford
Nintex Newbie

Re: Regex extract producing extra characters in the results [" "]

Jump to solution

Hi

my first reply will remove the additional spaces, but you have a collection after the regents so save the regret output into a collection variable and then use a collection operation to get the index of 0 from the collection

see ‌ if you need more info

Reply
kevyn_williams
Nintex Newbie

Re: Regex extract producing extra characters in the results [" "]

Jump to solution

Hi 

Your first reply did remove the whitespaces which is great, however the result when written to my sharepoint column still contains the additional [" "]

Please could you give a little more detail about the requirement for a collection operation? I've never used this before and am fairly new to nintex... 

Are you saying we need to save this variable to a collection and then select the item from the collection rather than from the variable?

Reply
paul_crawford
Nintex Newbie

Re: Regex extract producing extra characters in the results [" "]

Jump to solution

Exactly. Save this to a collection variable. Then create a integer or number variable and set this to a default value of 0. Then use a collection operation of get and use the number variable for the index and save this to a text variable and you should get the desired result.

Any more problems let me know

Get Outlook for iOS<https://aka.ms/o0ukef>

Reply
Automation Master
Automation Master

Re: Regex extract producing extra characters in the results [" "]

Jump to solution

Are you using Nintex for SP2013? If so, you could use the "Trim String" action to clean-up your leading/trailing spaces.

Reply
kevyn_williams
Nintex Newbie

Re: Regex extract producing extra characters in the results [" "]

Jump to solution

Sorry for slow reply - only just got around to testing this out. Even when I add the trimmed values to a collection ID, when I retrieve the collection ID it still has the extra ["    "]  around it... 

My steps are:

  • Set variable :
    • 'Project Current'
    • value: Current Item: Project
    • Info: this sets the value from SP column 'project', which currently contains the full 3 part string 'RANDOMSTRING1 - RANDOMSTRING2 - RANDOMSTRING3'
  • Regular Expression:
    • string: ‍{VariableSmiley Tongueroject Current}‍
    • Operation: extract
    • Pattern: (?<=- ).+(?= -)
    • output: 'ClientID_trimmed' (variable)
    • Info: this cleans the 3 part string and results in just the middle part, ie 'RANDOMSTRING2'
  • Add item to collection: 
    • target collection: ClientID_collection
    • Index: value 0
    • value: text: ‍{Variable:ClientID_trimmed}‍
    • output: ClientID_collection
  • Get item from collection:
    • target collection: ClientID_collection
    • index: value 0
    • output: ClientID_collectionvariable

I'd be grateful if you could cast your eyes over it and tell me if I've got a step wrong or out of order please! Of course let me know if I can provide more info

Many thanks

Reply
paul_crawford
Nintex Newbie

Re: Regex extract producing extra characters in the results [" "]

Jump to solution

Hi Kevyn Williams

I think you have to many steps. the output variable from the Regular Expression should be a collection variable.

Then just use the Get item from collection.

I have just tested this and have completed what you want in 2 steps. You can add the input text of the regular expression to be the Current Item: Project value. Although there is absolutely nothing wrong with storing it in a variable first.

Reply
kevyn_williams
Nintex Newbie

Re: Regex extract producing extra characters in the results [" "]

Jump to solution

This is the perfect solution, thank you so much for the detailed responses

Reply