Replace the first instance using regular expression action

  • 9 August 2019
  • 1 reply
  • 3 views

Badge +1

I am trying to remove the FIRST occurrence of a parenthesis in a string. Here is my input text:

Douglas Christopher W) I have some (comments) to add.

 

Using RegEx, I can use the Pattern       )

And the Replacement Text                     :

But that will change ALL the occurrences of the ) character, returning

Douglas Christopher W: I have some (comments: to add.

 

How do I turn off the global flag and just convert the first instance?

 


1 reply

Userlevel 6
Badge +22

Hi,

The Nintex Regular expression action uses .NET regular expression format.

There does not appear to be a way to turn of the /g global flag and that is why the regex matches all occurances and does not adhere to being lazy.

 

I was able to come up with a long and tedious workaround that does work.

First I use the regular expression ^[ws]+) that will find everything up to the first closing parentheses.

Extract that into its own collection variable.  Then use the same expression to replace that text with blank and put that into its own text vaiable.

Extract the the first part of the string from the collection and use a replace to alter the closing parentheses to a colon then use a build string to join the two halves back together again.

I have attached a sample workflow.  You could put all of this into a UDA or action set.

Reply