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

前端之家收集整理的这篇文章主要介绍了正则匹配电话号码,网址链接,Email地址前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

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

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

{

//@H_301_1@匹配网址链接

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

{

//@H_301_1@匹配电话号码

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

{

//@H_301_1@匹配Email@H_301_1@地址

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

NSArray *array_email = [text componentsMatchedByRegex:regex_email];

NSMutableArray *emailArr = [NSMutableArray arrayWithArray:array_email];

return emailArr;

}

原文链接:https://www.f2er.com/regex/361911.html

猜你在找的正则表达式相关文章