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

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

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

}

posted @ 2017-03-01 11:21  tiankongzhicheng  阅读(323)  评论(0编辑  收藏  举报