Re: Extracting substring with regexp



On Jan 31, 3:52 pm, Alex <aki...@xxxxxxxxx> wrote:
How to extract substring with regexp when we have start and end for
substring?
For example I want to find what is between "abc" and "xyz" in the
String.

  Pattern p = Pattern.compile("abc*xyz");
  Matcher m = p.matcher("aaaaaaaaaabc123xyzzzzzzzzzzzzz");

 but m.matches() returns false and can't find my patter.

 How can I get these "123" in this example?

Alex Kizub.

You could try grouping:

(a+bc)(.+)(xyz+)

group 2 is the one that would have what you want.
.