Unexpected behaviour of replace() function

  • 10 January 2018
  • 2 replies
  • 3 views

Badge +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

Userlevel 5
Badge +14

you have to escape backslash itself as well.

try

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

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...

Reply