我有一個正則表達式來檢查Max 70 alphanumeric characters and special characters: '/\\ - ; @ and space
爲此我使用下面的正則表達式模式 -無法在Objective C創建正則表達式
^[a-zA-Z0-9,.-\s'\\\/@]{0,70}$
請注意:在https://regex101.com作品完美的罰款測試此
而下面的代碼與字符串匹配它 -
NSString *String = [email protected]\\
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"^[a-zA-Z0-9,.-\s'\\\/@]{0,70}$" options:NSRegularExpressionCaseInsensitive error:&error];
NSAssert(regex, @"Unable to create regular expression");
NSRange textRange = NSMakeRange(0, string.length);
NSRange matchRange = [regex rangeOfFirstMatchInString:string options:NSMatchingReportProgress range:textRange];
最初人們展示自身逃脫與MESSAGE-
Assertion failure in +[UMValidations validateString:withPattern:]
Terminating app due to uncaught exception 'NSInternalInconsistencyException', reason: 'Unable to create regular expression
現在^[a-zA-Z0-9,.-\\s'\\\\//@]{0,70}$
而現在它導致崩潰時,這種模式適用於正則表達式測試儀大錯在哪發生的事情 - quence錯誤,我改變了格局。
請提供字符串文字與您所使用的正則表達式。 –
這個問題最有可能是由於反黑。在工作中有幾個級別的轉義:Objective-C,正則表達式和文字使用。因此,顯示錶達式如何在代碼中出現是很重要的。 – Codo
只是逃離破折號或將它放在字符類的開頭或結尾。 – Toto