2016-09-26 1 views

Répondre

0

Je ne pense pas. Peut-être que vous avez fait votre bibliothèque personnalisée pour le même. Aussi, je vais vérifier si je peux trouver ce type de bibliothèque ou de fonction et je vous le ferai savoir.

1

Utilisez NSRegularExpression pour créer un objet d'expression régulière.

exemple de code dans OC:

[NSRegularExpression regularExpressionWithPattern:@"Your regexp pattern" options:NSRegularExpressionCaseInsensitive error:nil]; 

NSString *str = @"your string to match"; 
NSRange matchResult = [regexp rangeOfFirstMatchInString:str options:kNilOptions range:NSMakeRange(0, [str length])]; 
if(matchResult.length > 0) { 
    // NSString match with the regular expression 
} else { 
    // NSString not match with the regular expression 
} 

exemple de code dans Swift

let regExp = try! NSRegularExpression(pattern: "Your pattern", options: .CaseInsensitive) 
let matchStr = "Your string" 
let matchResult = regExp.rangeOfFirstMatchInString(matchStr, options: NSMatchingOptions(rawValue: 0), range: NSMakeRange(0, matchStr.characters.count)) 
if matchResult.length > 0 { 
    // String match with regexp 
} else { 
    // String not match 
}