Gops AB Gops AB - 1 year ago 68
Java Question

Java - Pattern matching between the same pattern

My sample string:

a ghgduysgd a fdferfdf a bvfxbgdf a gdfgdfg

I need to find all the contents between a's.

I have
But it matches all the contents after a. But I want to find between a.

First iteration:

Second iteration:

I want to get data like the above for the manipulation. can you help with regex?

Answer Source

You alrady use a lookbehind in your regex, change it to also use a lookahead:


Then make the .* non-greedy to stop at the first available "ending" a:


EDIT: the a|$ is from tobias_k's comment below, originally it was just a

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