啥也不说了,在iOS中使用正则表达式;
-(void)parseString
{
//组装一个字符串,需要把里面的网址解析出来
NSString *urlString=@"sfdsfhttp://www.baidu.com http://www.google.com 11111111 33333 444444 555555 44";
NSError *error;
//http+:[^\\s]* 这个表达式是检测一个网址的。[0-9]{3,}
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"[0-9]{3,}"
options:0
error:&error];
NSLog( @"regex is %@", regex );
if (regex != nil)
{
NSArray *array = [regex matchesInString: urlString
options: 0
range: NSMakeRange( 0, [urlString length])];
NSLog( @"array is %@", array );
for (NSTextCheckingResult *match in array)
{
NSRange firstHalfRange = [match rangeAtIndex:0];
NSString *result1=[urlString substringWithRange:firstHalfRange];
//输出结果
NSLog(@"输出结果 %@",result1);
}
}
}