Regex for email address

前端 未结 4 1872
后悔当初
后悔当初 2020-12-29 23:13

Can someone show me a sample RegEx for an email address and how to use in in Objective-C?

Looking for something that fits: name@place.something

4条回答
  •  甜味超标
    2020-12-30 00:12

    NSString *string= @"my@mail.com her@mail.com him@mail.com";
    NSError *error = NULL;
    NSRegularExpression *regex = nil;
    regex = [NSRegularExpression regularExpressionWithPattern:@"\\w+@[a-zA-Z_]+?\\.[a-zA-Z]{2,6}"
                                                      options:NSRegularExpressionCaseInsensitive
                                                        error:&error];   
    NSUInteger numberOfMatches = 0;
    numberOfMatches = [regex numberOfMatchesInString:string
                                             options:0
                                               range:NSMakeRange(0, [string length])];
    NSLog(@"numberOfMatches is: %lu", numberOfMatches);
    

    There are more options of course. Read here.

提交回复
热议问题