2
我正在研究一個需要使用正則表達式驗證ipv4地址的iOS項目。通過正則表達式驗證IP地址 - 未知的轉義序列
我用下面的代碼
// only support ip4 currently
NSRegularExpression *regex = [NSRegularExpression
regularExpressionWithPattern:@"^(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)$"
options:0
error:nil];
NSUInteger numberOfMatches = [regex numberOfMatchesInString:IpString options:0 range:NSMakeRange(0, [IpString length])];
return (numberOfMatches==1?TRUE:FALSE);
的XCode保持警告我 「未知轉義序列。」。當我輸入「1.3.6.-6」或「2.3.33」時返回true。
如何在正則表達式中使用點(。)?謝謝