2012-04-13 71 views
0

我试图从一个音频流使用NSRegularExpression分割ICECAST数据,但我认为我有一个与我的模式的一般问题。NSRegularExpression模式为ICECAST数据

这里是我的代码:

NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"StreamTitle='(.*)';" 
                     options:NSRegularExpressionCaseInsensitive 
                     error:nil]; 

NSMutableString *messageAsText = [NSMutableString stringWithUTF8String:[messageAsRawData bytes]]; 
NSTextCheckingResult *match = [regex firstMatchInString:messageAsText 
               options:0 
                range:NSMakeRange(0, [messageAsText length])]; 
NSString *message = [messageAsText substringWithRange:[match rangeAtIndex:1]]; 
NSLog(@"Input: '%@', Output: '%@'", messageAsText, message); 

说输入的是:

StreamTitle='Thomas Newman - Awkward Talk [The Horse Whisperer]';StreamUrl=''; 

我希望得到这个:

Thomas Newman - Awkward Talk [The Horse Whisperer] 

,但我得到这个:

Thomas Newman - Awkward Talk [The Horse Whisperer]';StreamUrl=' 
http://regex.larsolavtorvik.com/

可能有人点我到正确的正则表达式:

这如果这里测试不NSRegularExpression相关的,因为正则表达式显示了同样的结果呢?

+0

BTW:在“ungreedy”选项强制所需的匹配...寻找在iOS中ungreedy选项... 示例PHP: preg_match_all('/ StreamTitle ='(。*)';/iU','StreamTitle ='Mychael和Jeff Danna - Camelot的大厅'; StreamUrl ='';',$ result); – decades 2012-04-13 22:31:29

+0

好的,快速找到和自己回答:一个小引号使窍门: 而不是 @“StreamTitle ='(。*)';” 我需要使用 @“StreamTitle ='(。*?)';” 话题关闭 – decades 2012-04-13 22:38:06

+0

你的意思是一个小问号? – borrrden 2012-04-14 01:49:08

回答

2

尝试使* quatifier懒惰通过与?这样它后面:

StreamTitle='(.*?)'