Extract text from between characters in string

jonathangilbert
Mega Sage

Hi,

 

I have been searching the community but not actually found the solution. I need to extract the text between the the 2 "|" as shown in the below example:-

 

TICKET ID 924209 | ABNORMAL_ANONYMOUS_IP | JOE BLOGGS
 
So i would expect "ABNORMAL_ANONYMOUS_IP" to be returned and then updated into the 
"u_report_name" field.
The TICKET ID number can change in length and also the text between the 2 "pipes" will also vary.
 
I have found a script on the forum which dealt with multiple emails in a string field,which I have ammended and shown below, but it does not work 
 
var str = 'TICKET ID 924209 | ABNORMAL_ANONYMOUS_IP | JOE BLOGGS';
var split1 = str.split(";");
var stringArray = [];
for(var i=0;i<split1.length-1;i++){
var initialString = split1[i];
var cat  = initialString.substring(initialString.indexOf("|") + 1, initialString.indexOf("|"));
stringArray.push(cat.toString());
}
current.u_report_name = cat;