fork download
  1. import java.util.regex.Matcher;
  2. import java.util.regex.Pattern;
  3. import java.text.Normalizer;
  4.  
  5. class Ideone
  6. {
  7. public static void main(String[] args) {
  8. String haystack[] = {"Apple","Apple","Apple"};
  9. String needle[] = {"ápple", "apple", "Applé"};
  10. for (int i = 0; i < haystack.length; i++) {
  11. System.out.println(
  12. find(
  13. normalize(haystack[i]),
  14. normalize(needle[i])
  15. )
  16. );
  17. }
  18. }
  19.  
  20. public static String normalize(String s) {
  21. return Normalizer.normalize(s, Normalizer.Form.NFD).replaceAll("\\p{Mn}", "");
  22. }
  23.  
  24. public static boolean find(String haystack, String needle) {
  25. Pattern p = Pattern.compile(needle, Pattern.CASE_INSENSITIVE);
  26. Matcher m = p.matcher(haystack);
  27. if (m.find()) {
  28. return true;
  29. } else {
  30. return false;
  31. }
  32.  
  33. }
  34. }
  35.  
Success #stdin #stdout 0.13s 321216KB
stdin
Standard input is empty
stdout
true
true
true