Instantly share code, notes, and snippets.

Embed
What would you like to do?
正则表达式一例
NSString *str = @"666666[url:mLbSZ9EFBHifL3QCnLAZ2Kw8r5z64x2LhhPoxiTSV+Y=]《恶魔总裁的祭品新娘》666666,666666[url:mLbSZ9EFBHhhhhhhhhhhh8r5z64x2LhhPoxiTSV+Y=]《龙娘777》666666,666666[url:mLbSZ9EFBHhhhshitshithhhh8r5z64x2LhhPoxiTSV+Y=]《😂神特么emoji里没有屎》666666";
NSString *regexStr = @"\\[url:[\\w+=]+]《.*?》";
NSError *error;
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:regexStr options:NSRegularExpressionDotMatchesLineSeparators error:&error ];
NSArray *arr = [regex matchesInString:str options:NSMatchingReportProgress range:NSMakeRange(0, str.length)];;
for (NSTextCheckingResult *match in arr) {
NSRange range = [match range];
NSString *mStr = [str substringWithRange:range];
NSLog(@"match: %@", mStr);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment