Link to home
Start Free TrialLog in
Avatar of MJ
MJFlag for United States of America

asked on

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
ASKER CERTIFIED SOLUTION
Avatar of Rob
Rob
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
And to answer your question, yes it does do a split in a sense
Avatar of MJ

ASKER

I get an error Regular Expression is invalid? Maybe this tool isn't using javascript regex?
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