-1
final String str = "I want to get previous or next string";
final Matcher matcher = Pattern.compile("or").matcher(str);
if(matcher.find()){
System.out.println(str.substring(matcher.end()).trim());
}

I want to get:"previous" or "next" strings

output: next string
Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
touchngo
  • 35
  • 1
  • 6

1 Answers1

-1

Group your regex and iterate through groups from the mathcher class. Google it regex grouping and iteration in java. get sample and do it.

Hakuna Matata
  • 755
  • 3
  • 13