fork(3) 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. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. final String functionNameRegex = "^(\\w+(\\s+)?){2,}\\([^!@\\#$+%^]*\\)";
  13. final String functionString = "public void render(int screenNo, String infoText){}";
  14.  
  15. final Pattern fnPattern = Pattern.compile(functionNameRegex, Pattern.CASE_INSENSITIVE | Pattern.COMMENTS);
  16. final Matcher fnMatcher = fnPattern.matcher(functionString);
  17.  
  18. while (fnMatcher.find()) {
  19. System.out.println("Full match: " + fnMatcher.group(0));
  20. for (int i = 1; i <= fnMatcher.groupCount(); i++) {
  21. System.out.println("Group " + i + ": " + fnMatcher.group(i));
  22. }
  23. }
  24. }
  25. }
Success #stdin #stdout 0.04s 4386816KB
stdin
Standard input is empty
stdout
Full match: public void render(int screenNo, String infoText)
Group 1: render
Group 2: