fork(1) download
  1. import java.util.*;
  2. import java.lang.*;
  3. import java.io.*;
  4. import java.util.regex.*;
  5.  
  6. class Ideone
  7. {
  8. public static void main (String[] args) throws java.lang.Exception
  9. {
  10. List<String> strs = Arrays.asList(
  11. "abcDE 123", // Yes, this should match
  12. "!@#$%^&*", // Yes, this should match
  13. "aaàààäää", // Yes, this should match
  14. "ベビードラ", // No, this shouldn't match
  15. "😀😃😄😆"); // No, this shouldn't match
  16. Pattern LatinPattern = Pattern.compile("^[\\p{InBasicLatin}\\p{InLatin-1Supplement}\\p{InLatinExtended-A}\\p{InLatinExtended-B}]+$");
  17. //Pattern LatinPattern = Pattern.compile("^[\\x00-\\x{024F}]+$"); //U+0000-U+024F
  18. for (String str : strs) {
  19. Matcher matcher = LatinPattern.matcher(str);
  20. if (!matcher.find()) {
  21. System.out.println(str + " => is NON Latin");
  22. //return;
  23. } else {
  24. System.out.println(str + " => is Latin");
  25. }
  26. }
  27. }
  28. }
Success #stdin #stdout 0.13s 36548KB
stdin
Standard input is empty
stdout
abcDE 123 => is Latin
!@#$%^&* => is Latin
aaàààäää => is Latin
ベビードラ => is NON Latin
😀😃😄😆 => is NON Latin