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

  • 21 July 2017
  • 8 replies
  • 10 views

Badge +3

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


8 replies

Userlevel 4
Badge +7

Hi Kevyn Williams

Try this

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

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

Hope this helps

Userlevel 4
Badge +7

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

Badge +3

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?

Userlevel 4
Badge +7

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>

Badge +8

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

Badge +3

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: ‍{Variable:Project 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

Userlevel 4
Badge +7

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.

Badge +3

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

Reply