- (NSString *)MyRegularExpressions:(NSString *)url { //remove <script></script> from comment content NSError *error = NULL; NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"<script[^>]*?>.*?</script>" options:NULL error:&error]; NSString *lowercaseString = [url lowercaseStringWithLocale:[NSLocale currentLocale]]; NSString *modifedContent = [regex stringByReplacingMatchesInString:lowercaseString options:0 range:NSMakeRange(0,[lowercaseString length]) withTemplate:@""]; NSString *finalUrl = nil; if (modifedContent.length < lowercaseString.length) { finalUrl = modifedContent; }else { finalUrl = url; } return finalUrl; }
謝謝 @彭博 的幫助~
url