Skip to main content
Nintex Community Menu Bar

Unexpected behaviour of replace() function

  • January 10, 2018
  • 2 replies
  • 22 views

Forum|alt.badge.img+1

Dear all,

I'm using Nintex Forms 2013 and the replace() function gives me some troubles.


I get a string like this, from an people picker field:


XXXXXX|YYYYYY|StringOfInterest

Where the length of the "XXXXXX" and "YYYYYY" substrings (at least to my knowledge) are not known. I want to extract the substring "StringOfInterest", i.e. replacing "XXXXXX|YYYYYY|" with "". I am using the expression  (.*|){2} , which does exactly what i want to, when i enter it on https://regexr.com/ , but if i use it in the replace function in a calculated field like so:

replace(PeoplePicker,"(.*|){2}","")

i always get an empty string (yes, PeoplePicker has a value in it). 

If i use something like this:

replace(PeoplePicker,"(.*|){2}","k")

i get the output:

k

,which implies that the expression matches, but disregards the umatched part of the source String. This sounds to me like a thing that the replace function shouldn't do, or did i misunderstand the replace function?
It would be nice if someone could shine a light on my lack of knowledge. happy.png

2 replies

Forum|alt.badge.img+14
  • Scholar
  • January 11, 2018

you have to escape backslash itself as well.

try

replace(PeoplePicker,"(.*\\|){2}","")

Forum|alt.badge.img+1
  • Author
  • January 11, 2018

hi marian,

Thanks for the hint.

replace(PeoplePicker, "(.*\|){2}" , "")

This did the job for me, though it is beyond me, why the escaped sequence "|" has to be escaped again...