Regex : How to split formatted string - non-greedy selecting

Viewed 15

I have these strings that I want to try to correctly extract:

{9|[ELX-P428AM,KLT-HP-9014DM]}
{15|[ELX-P429,KLT-HP2-901]}{18|[ELX-P427AM,KLT-HP-9015DM]}

The regex:

\{\d{1,}\|\[(.+)\]\}

I am trying to prevent the .+ (any length between [ and ] from being too 'greedy', I want to split the items from { to }.

Current Results:

[0]     {9|[ELX-P428AM,KLT-HP-9014DM]}

[0]     {15|[ELX-P429,KLT-HP2-901]}{18|[ELX-P427AM,KLT-HP-9015DM]}

Expected Results:

[0]     {9|[ELX-P428AM,KLT-HP-9014DM]}

[0]     {9|[ELX-P428AM,KLT-HP-9014DM]}
[1]     {9|[ELX-P428AM,KLT-HP-9014DM]}

Additionally, if I add a 'comma' between them:

\{\d{1,}\|\[(.+)\]\},

I only get the first result (second result is removed):

       {9|[ELX-P428AM,KLT-HP-9014DM]},{9|[ELX-P428AM,KLT-HP-9014DM]}


       becomes: 
{9|[ELX-P428AM,KLT-HP-9014DM]},

but missing second item : {9|[ELX-P428AM,KLT-HP-9014DM]} because of comma matching

Please assist, thank you!

0 Answers
Related