2016-09-26 29 views

回答

0

我不這麼認爲。可能是你已經使你的自定義庫相同。此外,我會檢查我是否可以找到這種類型的圖書館或功能,並會讓你知道。

1

使用NSRegularExpression來創建正則表達式對象。在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 
} 

示例代碼

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 
}