fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6. import java.util.regex.*;
  7.  
  8. /* Name of the class has to be "Main" only if the class is public. */
  9. class Ideone
  10. {
  11. public static void main (String[] args) throws java.lang.Exception
  12. {
  13. Pattern p = Pattern.compile("(j?(a?(va)))");
  14. Matcher m = p.matcher("this is java. this is ava, this is va");
  15.  
  16. while( m.find() )
  17. {
  18. String group = m.group();
  19. int start = m.start();
  20. int end = m.end();
  21. System.out.format("I found the text"
  22. + " \"%s\" starting at "
  23. + "index %d and ending at index %d.%n",
  24. group,
  25. start,
  26. end);
  27.  
  28.  
  29.  
  30. }
  31. }
  32. }
Success #stdin #stdout 0.12s 320576KB
stdin
Standard input is empty
stdout
I found the text "java" starting at index 8 and ending at index 12.
I found the text "ava" starting at index 22 and ending at index 25.
I found the text "va" starting at index 35 and ending at index 37.