fork download
  1. import java.util.regex.*;
  2. import java.util.*;
  3. import java.lang.*;
  4. import java.io.*;
  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. String regex = "[\\w&&[\\D]][\\w-]*";
  12. Pattern pattern = Pattern.compile(regex);
  13.  
  14. String s1 = "hello world";
  15. String s2 = "_Sau90-jds";
  16. String s3 = "5_idsjd";
  17. String s4 = "A-next";
  18.  
  19. ArrayList<String> list = new ArrayList<>();
  20. list.add(s1);
  21. list.add(s2);
  22. list.add(s3);
  23. list.add(s4);
  24.  
  25. for (String string : list) {
  26. Matcher matcher = pattern.matcher(string);
  27. if (matcher.matches()) {
  28. System.out.println(matcher.group(0));
  29. }
  30. }
  31. }
  32. }
Success #stdin #stdout 0.06s 2841600KB
stdin
Standard input is empty
stdout
_Sau90-jds
A-next