加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 百科 > 正文

正则匹配电话号码,网址链接,Email地址

发布时间:2020-12-14 01:52:43 所属栏目:百科 来源:网络整理
导读:#pragma mark - 正则匹配电话号码,网址链接, Email 地址 + ( NSMutableArray *)addHttpArr:( NSString *)text { // 匹配网址链接 NSString *regex_http = @"(https?|ftp|file)+://[^s]*" ; NSArray *array_http = [text componentsMatchedByRegex :regex

#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;

}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读