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.  
  7. import java.util.Arrays;
  8. import java.util.Collections;
  9. import java.util.List;
  10. import java.util.regex.Matcher;
  11. import java.util.regex.Pattern;
  12. import java.util.stream.Collectors;
  13.  
  14. /* Name of the class has to be "Main" only if the class is public. */
  15. class Ideone
  16. {
  17. public static void main (String[] args) throws java.lang.Exception
  18. {
  19. // your code goes here
  20. // your code goes here
  21. Pattern p = Pattern.compile("^(_\\w*)|(\\w*_{2,}+\\w*)|(\\w*_$)");
  22. Matcher m = p.matcher("test_test_test");
  23. System.out.println("Is string invalid: "+ m.matches());
  24.  
  25.  
  26. m = p.matcher("test_");
  27. System.out.println("Is string invalid: "+ m.matches());
  28.  
  29.  
  30. m = p.matcher("test_____test");
  31. System.out.println("Is string invalid: "+ m.matches());
  32. }
  33. }
Success #stdin #stdout 0.09s 34320KB
stdin
Standard input is empty
stdout
Is string invalid: false
Is string invalid: true
Is string invalid: true