about RegexKitLite linebreak
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 wo开发者_运维知识库rk. I use ([\s\S]*), also dosen't math [abc]. How can I match this text? thank you
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
@"\\[([^\\]]*)\\]" // \[ ( [ ^\] ] ) \]
精彩评论