【发布时间】:2015-10-13 07:17:11
【问题描述】:
与 Recursive pattern in regex 类似的问题,但在 Objective-C 中。
我想查找外括号的范围或子字符串。
示例输入:
NSString *input = @"{a {b c}} {d e}";
示例结果:
// yeah, I know, we can't put NSRange in an array, it is just to illustrate
NSArray *matchesA = @[NSMakeRange(0, 9), NSMakeRange(10, 5)]; // OK
NSArray *matchesB = @[NSMakeRange(1, 7), NSMakeRange(11, 3)]; // OK too
NSArray *outputA = @[@"{a {b c}}", @"{d e}"]; // OK
NSArray *outputB = @[@"a {b c}", @"d e"]; // OK too
不幸的是,NSRegularExpression 显然不接受?R。匹配外括号的任何替代方法?
【问题讨论】:
-
ICU 正则表达式风格不支持递归。您将需要“手动”解析字符串。仅供参考,您一定是指
(?R),而不是\R。
标签: objective-c regex nsregularexpression recursive-regex