技术正則表達式—匹配电话号码,网址链接,Email地址
Posted wzjhoutai
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了技术正則表達式—匹配电话号码,网址链接,Email地址相关的知识,希望对你有一定的参考价值。
#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地址的主要内容,如果未能解决你的问题,请参考以下文章