2

I am using following Regex:

NSString *pattern = @"KEYIDSTREQ(?<SpeakerID>.*?)#MEMNAMESTREQ(?<SpeakerName>.*?)#MEMSPEAKNUMSTREQ(?<SpeakerNumberToSpeak>.*?)#MEMTRSTREQ(?<Time>.*?)#REQLED(ON|OF)#TALKLED(ON|OF)#SUMLED(ON|OF)#STOPLED(ON|OF)LT(?<HexNo>.*?)";

NSError *error = nil;
NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:pattern options:NSRegularExpressionCaseInsensitive error:&error];

if(!error) {
    // My code...
}

It is working correctly with iOS 9.0+ but when I run this code with iOS 8.1+ then I am getting following error message:

Error Domain=NSCocoaErrorDomain 
Code=2048 "The operation couldn’t be completed. (Cocoa error 2048.)" 
UserInfo=0x16e19c60 {NSInvalidValue=KEYIDSTREQ(?<SpeakerID>.*?)#MEMNAMESTREQ(?<SpeakerName>.*?)#MEMSPEAKNUMSTREQ(?<SpeakerNumberToSpeak>.*?)#MEMTRSTREQ(?<Time>.*?)#REQLED(ON|OF)#TALKLED(ON|OF)#SUMLED(ON|OF)#STOPLED(ON|OF)LT(?<HexNo>.*?)}

What I am missing in that ? Any clue ?

Thomas Ayoub
  • 29,063
  • 15
  • 95
  • 142
SandeepM
  • 2,601
  • 1
  • 22
  • 32
  • 1
    Are you sure it worked at all? The last `.*?` never matched anything. Also, instead of `(ON|OF)`, you'd better use a simpler `O[NF]` – Wiktor Stribiżew Sep 05 '16 at 06:56
  • Yes, It works well with iOS 9.0+. I have tested with all the version. Try with this string: >KEYIDSTR=001^MEMNAMESTR=Member 1^MEMSPEAKNUMSTR=---^MEMTRSTR=0:00^REQLEDOF^TALKLEDOF^SUMLEDOF^STOPLEDOF<66 – SandeepM Sep 05 '16 at 07:10
  • Look, [there is no match](https://regex101.com/r/dY3vR9/1). – Wiktor Stribiżew Sep 05 '16 at 07:54
  • @wiktor, Please use this string: KEYIDSTREQ001#MEMNAMESTREQMember 1#MEMSPEAKNUMSTREQ---#MEMTRSTREQ1:00#REQLEDOF#TALKLEDOF#SUMLEDOF#STOPLEDOFLT67 Although, my question is not for matching, it gives error for iOS 8.0+ but for iOS 9.0+ its working fine. What is wrong here ? – SandeepM Sep 05 '16 at 08:24
  • 1
    Ok, then the issue is not related to the regex pattern itself. https://ideone.com/Iqd3No shows "nothing bad". – Wiktor Stribiżew Sep 05 '16 at 09:26
  • 1
    [Cocoa error 2048 when using NSRegularExpression in Cocoa](http://stackoverflow.com/questions/20640375/cocoa-error-2048-when-using-nsregularexpression-in-cocoa)? – Thomas Ayoub Sep 05 '16 at 12:08

0 Answers0