1
|
package com.mizo0203.timeline.talker.util;
|
2
|
|
3
|
import org.jetbrains.annotations.NotNull;
|
4
|
|
5
|
import java.util.regex.Matcher;
|
6
|
import java.util.regex.Pattern;
|
7
|
|
8
|
/** http://chat-messenger.net/blog-entry-40.html */
|
9
|
public class UrlUtil {
|
10
|
/** URLを抽出するための正規表現パターン */
|
11
|
@SuppressWarnings("Annotator")
|
12
|
private static final Pattern convURLLinkPtn =
|
13
|
Pattern.compile(
|
14
|
"(http://|https://){1}[\\w\\.\\-/:\\#\\?\\=\\&\\;\\%\\~\\+]+", Pattern.CASE_INSENSITIVE);
|
15
|
|
16
|
/**
|
17
|
* 指定された文字列内のURLを、正規表現を使用し、 空文字列に変換する。
|
18
|
*
|
19
|
* @param str 指定の文字列。
|
20
|
* @return リンクに変換された文字列。
|
21
|
*/
|
22
|
public static String convURLEmpty(@NotNull CharSequence str) {
|
23
|
Matcher matcher = convURLLinkPtn.matcher(str);
|
24
|
return matcher.replaceAll("");
|
25
|
}
|
26
|
}
|