【发布时间】:2015-04-16 12:43:21
【问题描述】:
考虑下面的代码
NSString* originalString = @"I love regex. regex is cool.";
NSString* regexString = [NSString stringWithFormat:@"(regex)"];
NSString* replaceWithString = @"[$1]";
NSString* finalString = [htmlString stringByReplacingOccurrencesOfRegex:regexString withString:replaceWithString];
输出是:
我喜欢 [正则表达式]。 [正则表达式] 很酷。
我想要的是
我喜欢 [正则表达式]。 [正则表达式] 很酷。
即 toUpperCase() 的 $1 类型组匹配。
看来我可以使用replacementStringForResult:inString:offset:template: 做到这一点,但不知道如何。有人可以帮忙吗?
【问题讨论】:
-
我不知道这是否适合你,但在许多语言中,你可以使用
\u\1或者\u$1
标签: objective-c regex uppercase