-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUnLinker.java
More file actions
40 lines (31 loc) · 914 Bytes
/
UnLinker.java
File metadata and controls
40 lines (31 loc) · 914 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import java.util.HashSet;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class UnLinker
{
// public static void main(String[] args)
// {
// System.out.println(clean("q,Rp3.tvt.ewwwww.ebwww.UQ.info5:.edup.tvwww.www.AW"));
// }
public static String clean(String text)
{
String prefix = "((http://)|(http://www\\.)|(www\\.))";
String mid = "([a-zA-Z0-9.]+)";
String suffix = "((\\.com)|(\\.org)|(\\.edu)|(\\.info)|(\\.tv))";
String regex = prefix + mid + suffix;
Pattern pattern;
Matcher matcher;
pattern = Pattern.compile(regex);
matcher = pattern.matcher(text);
StringBuilder sb = new StringBuilder();
int i = 0, c = 1;
while(matcher.find())
{
while(i < matcher.start()) sb.append(text.charAt(i++));
sb.append("OMIT" + c++);
i = matcher.end();
}
while(i < text.length()) sb.append(text.charAt(i++));
return sb.toString();
}
}