fork(1) 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.Matcher;
  7. import java.util.regex.Pattern;
  8.  
  9. /* Name of the class has to be "Main" only if the class is public. */
  10. class Ideone
  11. {
  12. public static void main (String[] args) throws java.lang.Exception
  13. {
  14. String line = "aluno/1/Teste dos Testes/1,2,33,3,4";
  15. String line2 = "aluno/1/Teste dos Testes/1,2,33,3,4a";
  16. String line3 = "aluno/1/Teste dos Testes/1,2,33,3,a";
  17. String line4 = "aluno/1/Teste dos Testes/1,2,33a,3";
  18. String pattern = "(\\/[\\d,]+\\d)$";
  19.  
  20. Pattern r = Pattern.compile(pattern);
  21.  
  22. Matcher i = r.matcher(line);
  23. Matcher i2 = r.matcher(line2);
  24. Matcher i3 = r.matcher(line3);
  25. Matcher i4 = r.matcher(line4);
  26.  
  27. if (i.find( )) {
  28. System.out.println("OK!");
  29. System.out.println("Valor encontrado: " + i.group(0) );
  30. }else{
  31. System.out.println("Inválido");
  32. }
  33.  
  34. if (i2.find( )) {
  35. System.out.println("OK!");
  36. }else{
  37. System.out.println("Inválido");
  38. }
  39.  
  40. if (i3.find( )) {
  41. System.out.println("OK!");
  42. }else{
  43. System.out.println("Inválido");
  44. }
  45.  
  46. if (i4.find( )) {
  47. System.out.println("OK!");
  48. }else{
  49. System.out.println("Inválido");
  50. }
  51. }
  52.  
  53.  
  54. }
Success #stdin #stdout 0.1s 28096KB
stdin
Standard input is empty
stdout
OK!
Valor encontrado: /1,2,33,3,4
Inválido
Inválido
Inválido