Graham Graham - 1 year ago 83
Java Question

Regex to parse strings that might or might not be delimited by ; into several groups

I have a case where I need to parse a string into several groups depending on a criteria

For example the below;


should be 2 groups


Notice that I dont care about 01 at the beginning and there can be 0 or more substrings delimited by ; and I need them all in their own group.

Another one;


should be 3 groups:


Basically, I dont need to care if alpha or numeric comes first. The issue is grouping expressions into their own which can be 0 or more times. Meaning the below


should produce also one group of

Answer Source

So I guess you need a regexp analog of split. That would require a repeated capturing group.

Bad news, some people have looked into a similar problem and haven't found the right answer:

Good news, if you can live with some reasonable limit on the number of groups and you can add some code to identify the empty trailing ones, this may help:

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download