0

I'm use RegexKitLite to match some texts:

xxx*[abc]*xxx

and I want to match [abc],and use this regular:

NSString *result = [@"xxx[abc]xxx" stringByMatching:@"\\[(.*)?\\]" capture:1];

then, the result is [abc].But, if have linebreak in there:

xxx[ab c]xxx

It's dosen't work. I use ([\s\S]*), also dosen't math [abc]. How can I match this text? thank you

user847556
  • 11
  • 3

1 Answers1

0

The . does not match new lines by default. You could use

 ... stringByMatching:@"(?s:\\[(.*)?\\])" ...
//                      ^^^^           ^

or supply the RKLDotAll option with the -stringByMatching:options:inRange:capture:error: method.

Alternatively, you could use the greedy variant

@"\\[([^\\]]*)\\]"   // \[  (  [ ^\] ]  )   \]
kennytm
  • 510,854
  • 105
  • 1,084
  • 1,005