0

I have NSString that contain this string :

c&&(b.signature=Rk(c));return ql(a,b)}

The RK can be any two chars.

I try to get the RK from the string with (RegexKitLit):

NSString *functionCode = [dataStr2 stringByMatching:@".signature=(.*?)\(" capture:1L];

and functionCode is always nil.Any idea what wrong?

3
  • 1
    If you know where the 2 characters you want are, why do you need a regex? Commented Jan 26, 2014 at 14:48
  • i wrote that it can be Rk and it can be tU or any other two letters Commented Jan 26, 2014 at 14:49
  • 1
    But since you know WHERE they are, can't you just extract the characters at those positions? Commented Jan 26, 2014 at 14:55

1 Answer 1

1

Don't bother with regular expressions for this. If the format of the string is always the same then you can simply do:

NSString *dataStr2 = @"c&&(b.signature=Rk(c));return ql(a,b)}";
NSString *functionCode = [dataStr2 substringWithRange:NSMakeRange(16, 2)];

If the string is not quite so fixed then base it on the position of the =.

NSString *dataStr2 = @"c&&(b.signature=Rk(c));return ql(a,b)}";
NSRange equalRange = [dataStr2 rangeOfString:@"="];
NSString *functionCode = [dataStr2 substringWithRange:NSMakeRange(equalRange.location + equalRange.length, 2)];
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.