需求:
- 針對+86 123234534或+886 097xxxxx
大概的寫法是:
NSError *error = NULL;
NSRegularExpression *regex
= [NSRegularExpression regularExpressionWithPattern:@"^[\\+][0-9]+(\\s)|^[\\+]" options:NSRegularExpressionCaseInsensitive error:&error];
NSString *mobile = @"+86 123456789";
NSString *modifiedString = [regex stringByReplacingMatchesInString: mobile options:0 range:NSMakeRange(0, [mobileChanged length]) withTemplate:@""];
NSLog(@"%@", modifiedString);
這樣就ok了~
參考網址:
NSRegularExpression Class Reference
User regular expression to find/replace substring in NSString
沒有留言:
張貼留言