Android/Android Java
[Android Java] URL 유무 및 추출
Bell91
2023. 10. 27. 11:49
반응형
Code
//Url만 있는지 없는지 확인, Url만 true, Url + 기타는 false 20221027 LHJ
public static boolean CheckOnlyUrl(final String requestUrl){
boolean checkOnlyUrl = false;
//Url 뽑아내는 작업
try {
String REGEX = "[(http(s)?):\\/\\/(www\\.)?a-zA-Z0-9@:%._\\+~#=]{2,256}\\.[a-z]{2,6}\\b([-a-zA-Z0-9@:%_\\+.~#?&//=]*)";
Pattern p = Pattern.compile(REGEX, Pattern.CASE_INSENSITIVE);
Matcher m = p.matcher(requestUrl);
if (m.find()) {
String host = m.group();
requestUrl = requestUrl.replaceAll(host, "").trim();
}
} catch (Exception e) {
e.printStackTrace();
}
//Emoji Check
Pattern rex = Pattern.compile("[\\x{10000}-\\x{10ffff}\ud800-\udfff]");
//Emoji Check and remove
Matcher rexMatcher = rex.matcher(requestUrl);
if(rexMatcher.find()){
requestUrl = EmojiParser.removeAllEmojis(requestUrl).trim();
}
if(requestUrl.length() > 0){
checkOnlyUrl = false;
}else {
checkOnlyUrl = true;
}
return checkOnlyUrl;
}
1. url 유무 체크
2. url이 있으면 true 리턴
3. url이 없으면 false 리턴
Reference
https://jizard.tistory.com/237
반응형