Created
August 6, 2012 15:18
-
-
Save kmussel/3275417 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Parsing URLS OUT: | |
NSArray *comp = [self.shareView.textView.text componentsSeparatedByString:@" "]; | |
NSRegularExpression *expression = [NSRegularExpression regularExpressionWithPattern:@"(?i)\\b((?:[a-z][\\w-]+:(?:/{1,3}|[a-z0-9%])|www\\d{0,3}[.]|[a-z0-9.\\-]+[.][a-z]{2,4}/)(?:[^\\s()<>]+|\\(([^\\s()<>]+|(\\([^\\s()<>]+\\)))*\\))+(?:\\(([^\\s()<>]+|(\\([^\\s()<>]+\\)))*\\)|[^\\s`!()\\[\\]{};:'\".,<>?«»“”‘’]))" options:NSRegularExpressionCaseInsensitive error:NULL]; | |
nonCountingChars = 0; | |
replaceCnt = 0; | |
if(comp.count) | |
{ | |
[linklist removeAllObjects]; | |
for(NSString *txt in comp) | |
{ | |
if(txt.length > 5) | |
{ | |
NSRange rng = [expression rangeOfFirstMatchInString:txt options:NSMatchingCompleted range:NSMakeRange(0, [txt length])]; | |
if(rng.length>0) | |
{ | |
nonCountingChars += rng.length; | |
if(replace) | |
{ | |
replaceCnt++; | |
NSString *match = [txt substringWithRange:rng]; | |
[self.linklist addObject:match]; | |
self.shareView.textView.text = [self.shareView.textView.text stringByReplacingOccurrencesOfString:match withString:@"[LINK]"];//:rng withString:@"{LINK}"]; | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment