-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExtractURLs.cls
More file actions
23 lines (19 loc) · 769 Bytes
/
ExtractURLs.cls
File metadata and controls
23 lines (19 loc) · 769 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
public class ExtractURLs {
/* regular expression used to find URL in a body of text */
public static List<String> ParseText(String regex) {
// credit to Stackoverflow for the regular expression
String regexExpression = '(?:^|[\\W])((ht|f)tp(s?):\\/\\/|www\\.)'
+ '(([\\w\\-]+\\.){1,}?([\\w\\-.~]+\\/?)*'
+ '[\\p{Alnum}.,%_=?&#\\-+()\\[\\]\\*$~@!:/{};\']*)';
Pattern myPatter = Pattern.compile(regexExpression);
Matcher myMatch = myPatter.matcher(regex);
List<String> foundUrls = new List<String>();
while (myMatch.find()) {
//system.debug(myMatch.group());
String matches = myMatch.group();
foundUrls.add(matches);
system.debug('what urls were found: ' + foundUrls);
}
return foundUrls;
}
}