fork(1) 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. System.out.println("Result is " + isGmail("stackoverflow@gmail.com"));
  12. }
  13.  
  14. public final static boolean isGmail(String s) {
  15.  
  16. Pattern pattern = Pattern.compile("(\\W|^)[\\w.+\\-]*@gmail.com(\\W|$)");
  17. System.out.println(pattern + " pp ");
  18. Matcher m = pattern.matcher(s);
  19. System.out.println(m + " pp ");
  20. boolean b = m.matches();
  21. System.out.println(b + " pp ");
  22. return b;
  23. }
  24. }
Success #stdin #stdout 0.08s 380224KB
stdin
Standard input is empty
stdout
(\W|^)[\w.+\-]*@gmail.com(\W|$)            pp  
java.util.regex.Matcher[pattern=(\W|^)[\w.+\-]*@gmail.com(\W|$) region=0,23 lastmatch=]            pp  
true            pp  
Result is true