Possible Duplicate:
Parsing HTML NSRegularExpression
I have an NSString like this:
NSString *string = @"<a href='http://john.com'>JOHN</a> http://john.com";
I want to use a regex to parse out the URLS not in an anchor tag, so I can put them in an anchor tag.
I currently have this:
NSRegularExpression *URLRegex = [NSRegularExpression
regularExpressionWithPattern:@"((https?):\\/\\/[-A-Z0-9+&@#\\/%?=~_|!:,.;]*[-A-Z0-9+&@#\\/%=~_|])" options:NSRegularExpressionCaseInsensitive error:nil];
This does detect the URLS but it also detects the URLS in an anchor tag, which is problematic.
Does anyone know what I need to do? Thanks.
UPDATE:
@"([^\'](https?):\\/\\/[-A-Z0-9+&@#\\/%?=~_|!:,.;]*[-A-Z0-9+&@#\\/%=~_|][^\'])"
This pattern supplied by Alex below, is an improvement. But if I have a string like this @"http://example.com; john.com"; - example.com is matched. How can I exclude that? Basically I don't want anything in an anchor tag to be matched.