首页 > 其他 > 详细

【技术】正則表達式—匹配电话号码,网址链接,Email地址

时间:2017-08-10 11:11:54      阅读:191      评论:0      收藏:0      [点我收藏+]

#pragma mark - 正则匹配电话号码。网址链接。Email地址

+ (NSMutableArray *)addHttpArr:(NSString *)text

{

    //匹配网址链接

    NSString *regex_http = @"(https?|ftp|file)+://[^\\s]*";

    NSArray *array_http = [text componentsMatchedByRegex:regex_http];

    NSMutableArray *httpArr = [NSMutableArray arrayWithArray:array_http];

    return httpArr;

}


+ (NSMutableArray *)addPhoneNumArr:(NSString *)text

{

    //匹配电话号码

    NSString *regex_phonenum = @"\\d{3}-\\d{8}|\\d{3}-\\d{7}|\\d{4}-\\d{8}|\\d{4}-\\d{7}|1+[358]+\\d{9}|\\d{8}|\\d{7}";

    NSArray *array_phonenum = [text componentsMatchedByRegex:regex_phonenum];

    NSMutableArray *phoneNumArr = [NSMutableArray arrayWithArray:array_phonenum];

    return phoneNumArr;

}


+ (NSMutableArray *)addEmailArr:(NSString *)text

{

    //匹配Email地址

    NSString *regex_email = @"\\w+([-+.]\\w+)*@\\w+([-.]\\w+)*.\\w+([-.]\\w+)*";

    NSArray *array_email = [text componentsMatchedByRegex:regex_email];

    NSMutableArray *emailArr = [NSMutableArray arrayWithArray:array_email];

    return emailArr;

}

【技术】正則表達式—匹配电话号码,网址链接,Email地址

原文:http://www.cnblogs.com/wzjhoutai/p/7338056.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!