首页 > 代码库 > 根据正则表达式过滤非法的字符串

根据正则表达式过滤非法的字符串

//根据正则表达式过滤非法的字符串

+ (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;

}

根据正则表达式过滤非法的字符串