last day (15 days later) » 

11:56 AM
Hey
 
hey
 
Could you please help me out
I am in office and stuck
 
What was wrong with deny's answer?
 
var str1 = "121r3p|6547r|12345\\|abcd";
var str2 = "121r3!!#$|6547r!@|12345\\|abcd";

One regex that can solve
Expected OP:
first one: ["121r3p", "6547r", "12345\|abcd"]
second one: ['121r3!!#$', '6547r!@', '12345\|abcd']
console.log(str1.split(/\|/));
Your code is working fine for second
but not for first
 
/([^\\|]|\\.)+/g
Use deny's solution.. you get what you're aiming for
it works for both
if that isn't satisfactory, you have to tell me why
 
12:03 PM
console.log(str1.split(/([^\\|]|\\.)+/g));
// ["", "p", "|", "r", "|", "d", ""]
Sorry not match the expected OP
Thanks
 
Use match, not split
str1.match(/([^\\|]|\\.)+/g)
 

last day (15 days later) »