我试图利用NSRegularExpression从一个声音流中提取海经会数据,但我认为我有一般问题。
我的守则是:
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=
This is not NSRegularExpression related, because the regexp shows the same result if tested here: http://regex.larsolavtorvik.com/
没有人会向我指出正确的reg?