I've implemented NSDataDetector
to detect URLs, but it includes email addresses as well. Is there an easy way to make it not detect emails, but all other URLs?
Asked
Active
Viewed 744 times
1

jscs
- 63,694
- 13
- 151
- 195

user212541
- 1,878
- 1
- 21
- 30
-
See Dave DeLong's answer to this stack overflow question: [NSDataDetector with NSTextCheckingTypeLink detects URL and PhoneNumbers!](http://stackoverflow.com/questions/5965844/nsdatadetector-with-nstextcheckingtypelink-detects-url-and-phonenumbers). You want to pull out all the URLs and then filter on the URL scheme. – Apr 04 '13 at 21:09
1 Answers
1
Well, email addresses are not URLs. mailto:someone@some.where.com
is a URL which contains an email address. So, to answer your question: Check whether your URL begins with mailto:
. If it does, ignore it. If for some reason you're picking up email addresses as URLs, you probably have some parsing bug...
See here about regular expressions for URLs.
-
Data detectors were created specifically to detect things like emial addresses that aren't in URL form. – Jon Shier Apr 04 '13 at 19:38
-
@jshier: I'm not much of an iOS developer, but [this](https://developer.apple.com/library/mac/#documentation/Foundation/Reference/NSDataDetector_Class/Reference/Reference.html) says they're used for URLs also. – einpoklum Apr 04 '13 at 19:50