boolean (@NotNull String s) { boolean hasReChars = false; for (int i = 0, len = s.length(); i < len; i++) { final char c = s.charAt(i); if (c == ' ' || c == '_' || c == '-' || Character.isLetterOrDigit(c)) continue; hasReChars = true; break; } if (hasReChars) { try { //noinspection ResultOfObjectAllocationIgnored new URL(s); } catch (MalformedURLException e) { return true; } } return false; }