How to split using backslash (\)

ramesh_r
Mega Sage

Hi All,

 

I want to split the string using a backslash (\)  and i need value after the backslash  (\)

but I am not getting proper output

Expected output  ==   "_DJ_Ima_KPI-Rap"

var group = "GROUP\_DJ_Ima_KPI-Rap";
var n = group.split("\");
gs.log(n[0]);
gs.log(n[1]);

The expected output is : 

GROUP
_DJ_Ima_KPI-Rap
10 REPLIES 10

Community Alums
Not applicable

Hi,

How to separate incoming value dynamically here(like incoming value will be of the form sourceValue(domain\username or might be only username)) and i need to extract only username here.

Note:-incoming value will be type "domain\username username" only

var str = "domain\username ";//i'll be assigning with "domain\username "= sourceValue which is dynamic
var n=str.split("\\");
var domain= n[0]; //It is the 1st element
var userName= n[1]; //it is the 2nd element in the array

if(userName!=null)
{
gs.log(userName);
}
else
{
gs.log(domain);
}

 

I'm using this code and getting domainusername as output .expected was only username

 

How to solve this to get only username?