正则表达式中支持[ ]等转义词

问题,我想查找诸如13[attach]的字符串(前面数字不定),在如下构建正则时失败,因为在ios中不支持\[转义词,需要使用\\u005B替代

NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"[0-9]+\[/attach\]" options:

NSRegularExpressionCaseInsensitive

 error:nil];

 

需要改为

NSRegularExpression *regex = [NSRegularExpression regularExpressionWithPattern:@"[0-9]+\\u005B/attach\]" options:

NSRegularExpressionCaseInsensitive

 error:nil];

posted on 2014-11-13 15:48  trako  阅读(250)  评论(0编辑  收藏  举报

导航