fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. String regex = "[^-]*(-[^-]+)*-?;.*";
  13. String[] data = (
  14. "; -- a : should match\r\n"
  15. + "-- a ; : should not match\r\n"
  16. + "-- ; : should not match\r\n"
  17. + "--; : should not match\r\n"
  18. + "-;- : should match\r\n"
  19. + "---; : should not match\r\n"
  20. + "-- semicolon ; : should not match\r\n"
  21. + "bla : should not match (; is mandatory)\r\n"
  22. + "-;--; : should match (the first occuring semicolon must not have two or more consecutive leading '-')\r\n"
  23. + "--;--; : should match (the first occuring semicolon must not have two or more consecutive leading '-')\r\n"
  24. + "--;-; : should match (the first occuring semicolon must not have two or more consecutive leading '-')\r\n"
  25. + "bla ; bla : should match").split("(?m)\\s*:.*$(\r\n)?");
  26.  
  27. for (String s : data)
  28. System.out.printf("%-15s -> %b%n",s,s.matches(regex));
  29.  
  30. }
  31. }
Success #stdin #stdout 0.08s 380224KB
stdin
Standard input is empty
stdout
; -- a          -> true
-- a ;          -> false
-- ;            -> false
--;             -> false
-;-             -> true
---;            -> false
-- semicolon ;  -> false
bla             -> false
-;--;           -> true
--;--;          -> false
--;-;           -> false
bla ; bla       -> true