2016-09-26 102 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 
}