fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.util.regex.*;
  5. import java.lang.*;
  6. import java.io.*;
  7.  
  8. /* Name of the class has to be "Main" only if the class is public. */
  9. class Ideone
  10. {
  11. static Pattern pattAlphaNum = Pattern.compile("[A-Z|a-z|\\d+]");
  12. static Pattern pattAlpha = Pattern.compile("[A-Z|a-z]");
  13. static Pattern pattNum = Pattern.compile("[\\d+]");
  14.  
  15. static Pattern alternativo = Pattern.compile("([A-Za-z]|\\d+)");
  16. static Pattern semParenteses = Pattern.compile("[A-Za-z]|\\d+");
  17.  
  18. static void testar(String s) {
  19. System.out.print(s + "\t\t\t");
  20.  
  21. System.out.print(pattAlphaNum.matcher(s).matches() + "\t\t");
  22. System.out.print(pattAlpha.matcher(s).matches() + "\t");
  23. System.out.print(pattNum.matcher(s).matches() + "\t\t");
  24.  
  25. System.out.print(alternativo.matcher(s).matches() + "\t\t");
  26. System.out.print(semParenteses.matcher(s).matches() + "\n");
  27. }
  28.  
  29. public static void main (String[] args) throws java.lang.Exception
  30. {
  31. System.out.println("String\t\tAlphaNum\tAlpha\tNum\t\t\tSugestão\tSem Parênteses");
  32. testar("A");
  33. testar("a");
  34. testar("0");
  35. testar("aa");
  36. testar("10");
  37. testar("+");
  38. testar("|");
  39. }
  40. }
Success #stdin #stdout 0.07s 380224KB
stdin
Standard input is empty
stdout
String		AlphaNum	Alpha	Num			Sugestão	Sem Parênteses
A			true		true	false		true		true
a			true		true	false		true		true
0			true		false	true		true		true
aa			false		false	false		false		false
10			false		false	false		true		true
+			true		false	true		false		false
|			true		true	false		false		false