Regex not working as I thought

I got this regex from a previous post which worked but is not performing the way I thought it would when I test it in a tool I'm using (see attached).
[^|]+

Open in new window

Will split string into pieces based on the pipe separator or am I wrong? I only get back-reference $0 from it when testing and should see all back-references in the tool. The string can have N  number of pipe separators but I only care about $2. What is the regex that performs that.

abc|def|ghi
abc|def|ghi|jkl
123|456|789
123|456|789|101112
one1|two2|3three|4four|five5
sampleRegexIssue.png
894359Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

RobOwner (Aidellio)Commented:
It's just a matter of specifying the global parameter

/[^|]+/g

Given this is for javascript you should use the example I gave here http://jsbin.com/eneyORE/1/edit

And here: http://jsfiddle.net/6baBw/

var str ="one1|two2|3three|4four|five5";

document.write(str.match(/[^|]+/g)[0]);
document.write('<br/>');
document.write(str.match(/[^|]+/g)[1]);
document.write('<br/>');
document.write(str.match(/[^|]+/g)[2]);
document.write('<br/>');
document.write(str.match(/[^|]+/g)[3]);
document.write('<br/>');
document.write(str.match(/[^|]+/g)[4]);

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
RobOwner (Aidellio)Commented:
And to answer your question, yes it does do a split in a sense
0
894359Author Commented:
I get an error Regular Expression is invalid? Maybe this tool isn't using javascript regex?
0
RobOwner (Aidellio)Commented:
That site you were using is good for testing reg expressions but applying them to JavaScript you need to apply the expression in the right format using the // and g etc
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.