fork download
  1. import java.util.regex.Matcher;
  2. import java.util.regex.Pattern;
  3.  
  4. public class RegexMatches
  5. {
  6. public static void main( String args[] ){
  7.  
  8. // String to be scanned to find the pattern.
  9. String line = "This order was placed for QT3000! OK?";
  10. String pattern = "(.*)(\\d+)(.*)";
  11.  
  12. // Create a Pattern object
  13. Pattern r = Pattern.compile(pattern);
  14.  
  15. // Now create matcher object.
  16. Matcher m = r.matcher(line);
  17. if (m.find( )) {
  18. System.out.println("Found value: " + m.group(0) );
  19. System.out.println("Found value: " + m.group(1) );
  20. System.out.println("Found value: " + m.group(2) );
  21. } else {
  22. System.out.println("NO MATCH");
  23. }
  24. }
  25. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:4: error: class RegexMatches is public, should be declared in a file named RegexMatches.java
public class RegexMatches
       ^
1 error
stdout
Standard output is empty