我正在尝试删除字符串中的任何非字母数字字符。我尝试了以下代码片段,但它没有替换适当的字符。
NSString *theString = @"\"day's\"";
NSError *error = NULL;
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"^\\B\\W^\\B" options:NSRegularExpressionCaseInsensitive error:&error];
NSString *newString = [regex stringByReplacingMatchesInString:theString options:0 range:NSMakeRange(0, [theString length]) withTemplate:@""];
NSLog(@"the resulting string is %@", newString);