Open Chirag89-JackSparrow opened 6 years ago
@hsusmita @thelastjedi @georgesteiner @andreyoshev Did you check the above issue ?
@Chirag89-JackSparrow I am currently looking into this issue. Can you tell me if it works if you add detection for email only?
Actually I resolve issue by yesterday by changing regular expressions. Thanks for responding @hsusmita . The problem is, if there is no space before @, still it consider as user tag, and link portion so I change regular expression and of hashtag, user tag and link and implement in methods.
static NSString *kRegexStringForHashTag = @"(?<!\\w)(#(?:[a-z0-9A-Z].*?|\\d+[a-z0-9A-Z]+.*?))\\b";
static NSString *kRegexStringForUserHandle = @"(?<!\\w)(@(?:[a-z0-9A-Z].*?|\\d+[a-z0-9A-Z]+.*?))\\b";
static NSString *kRegexStringForURLLinkHandle = @"((((https?|ftp|gopher|telnet|file):((//)|(\\\\)))|((www|ftp)\\.))+[\\w\\d:#@%/;$()~_?\\+-=\\\\\\.&]*)";
Changes in methods
- (void)enableURLDetectionWithAttributes:(NSDictionary*)dictionary {
NSError *error;
NSRegularExpression *regex = [[NSRegularExpression alloc]initWithPattern:kRegexStringForURLLinkHandle options:0 error:&error];
PatternDescriptor *descriptor = [[PatternDescriptor alloc]initWithRegex:regex
withSearchType:PatternSearchTypeAll
withPatternAttributes:dictionary];
[self enablePatternDetection:descriptor];
}
- (void)disableURLDetection {
[self disablePatternDetection:[self.patternDescriptorDictionary objectForKey:kRegexStringForURLLinkHandle]];
}
- (void)enableHashTagDetectionWithAttributes:(NSDictionary*)dictionary {
NSError *error;
NSRegularExpression *regex = [[NSRegularExpression alloc]initWithPattern:kRegexStringForHashTag options:0 error:&error];
PatternDescriptor *descriptor = [[PatternDescriptor alloc]initWithRegex:regex
withSearchType:PatternSearchTypeAll
withPatternAttributes:dictionary];
[self enablePatternDetection:descriptor];
}
- (void)disableHashTagDetection {
[self disablePatternDetection:[self.patternDescriptorDictionary objectForKey:kRegexStringForHashTag]];
}
- (void)enableUserHandleDetectionWithAttributes:(NSDictionary*)dictionary {
NSError *error;
NSRegularExpression *regex = [[NSRegularExpression alloc]initWithPattern:kRegexStringForUserHandle
options:0
error:&error];
PatternDescriptor *descriptor = [[PatternDescriptor alloc]initWithRegex:regex
withSearchType:PatternSearchTypeAll
withPatternAttributes:dictionary];
[self enablePatternDetection:descriptor];
}
- (void)disableUserHandleDetection {
[self disablePatternDetection:[self.patternDescriptorDictionary objectForKey:kRegexStringForUserHandle]];
}
So now email detection is work perfect for me.
NSString *emailRegexString = @"[A-Z0-9a-z._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,4}";
NSError *error;
NSRegularExpression *regex = [[NSRegularExpression alloc]initWithPattern:emailRegexString
options:0
error:&error];
PatternDescriptor *descriptor = [[PatternDescriptor alloc]initWithRegex:regex withSearchType:PatternSearchTypeAll
withPatternAttributes:@{NSForegroundColorAttributeName:[UIColor greenColor]}];
[self.postDetailsL enablePatternDetection:descriptor];
@Chirag89-JackSparrow Cool! Thanks for updating. 👍
You can help with me for this issue @hsusmita @thelastjedi @georgesteiner @andreyoshev
When I add user tag and hashtag detection in custom tableview cell label and I scroll the tableview, sometimes user tag and hashtag is not detected. But when I scroll up its come as detected. Didn't found why it happens.
I have attach screen shots. Please check and let me know.
@Chirag89-JackSparrow I will look into this.
@hsusmita Let me know as soon as possible. Thanks for responding.
@hsusmita Any update on the above issue as we discussed ? I can't able to resolve this from my end.
@Chirag89-JackSparrow I didn't get time to update this. However, this library is breaking for ios 12. Can you try the swift version SwiftResponsiveLabel
?
I add email detection, url detection and userhandler detection on same label but its not working properly. When i add chirag@y.com its take @y as a userhandler detection part and chirag & .com as a url detection part. So it's not detect chirag@y.com as email part.