0

I'm trying to split string with "&&" operator. but in my string there is some data with the same "&&" operator which I don't want to split. so is there any way or logic to ignore that operator for split data.

string -

let str = "countryid == 45 && (payerid==82||payerid==84||payerid==79) && (fobid!=1&&fobid!=2)"

Code -

let breakCond = str.split('&&');

Result -

0: "countryid == 45 "
1: " (payerid==82||payerid==84||payerid==79) "
2: " (fobid!=1"
3: "fobid!=2) "

Expected Result -

0: "countryid == 45 "
1: " (payerid==82||payerid==84||payerid==79) "
2: " (fobid!=1&&fobid!=2) "
R. Richards
  • 24,603
  • 10
  • 64
  • 64

2 Answers2

0

It seems you could simply include the white spaces.

let breakCond = str.split(' && ');

If that doesn't do it than you would have to create your own version of split with its own logic.

New Rhino
  • 319
  • 3
  • 11
0

if there are always no spaces in the ones you want to keep. you can just use:

str.split(' && ')
Aizaz
  • 33
  • 7