//根据正则表达式过滤非法的字符串
+ (NSString *)filterCharactor:(NSString *)str withRegexString:(NSString *)regexStr
{
NSError * error = nil;
NSRegularExpression * expression = [NSRegularExpression regularExpressionWithPattern:regexStr options:NSRegularExpressionCaseInsensitive error:&error];
NSString * last=[expression stringByReplacingMatchesInString:str options:NSMatchingReportCompletion range:NSMakeRange(0, str.length) withTemplate:@""];
return last;
}
本文介绍了一个使用正则表达式过滤非法字符串的方法。通过NSRegularExpression类,该方法能够识别并移除不符合预设模式的字符,确保字符串的合法性。

被折叠的 条评论
为什么被折叠?



