fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.regex.Matcher;
  4. import java.util.regex.Pattern;
  5.  
  6. /* Name of the class has to be "Main" only if the class is public. */
  7. class Ideone
  8. {
  9. public static void main (String[] args) throws java.lang.Exception
  10. {
  11. String text = "<parent>\n"
  12. + " <child>SomeText</child>sometext<otherChild>sometext</otherChild>\n"
  13. + " <child>SomeText2</child>somtext2<otherChild>sometext2</otherChild>\n"
  14. + "</parent>";
  15. String regex = "<\\/child>(.*?<\\/otherChild>)";
  16. Pattern pattern = Pattern.compile(regex);
  17. Matcher matcher = pattern.matcher(text);
  18. while(matcher.find()){
  19. System.out.println(matcher.group(1));
  20. }
  21. }
  22. }
Success #stdin #stdout 0.1s 27836KB
stdin
Standard input is empty
stdout
sometext<otherChild>sometext</otherChild>
somtext2<otherChild>sometext2</otherChild>