我目前有以下正则表达式:
static inline NSRegularExpression * AuthorRegularExpression() {
if (!__authorRegularExpression) {
__authorRegularExpression = [[NSRegularExpression alloc] initWithPattern:@"-\\s*(.)*$" options:NSRegularExpressionCaseInsensitive error:nil];
}
return __authorRegularExpression;
}
正如您在模式中看到的那样,它会检测到破折号( - )后跟一些字符串。 但是现在我已经将短划线的格式更改为em-dash。所以字符串如下所示:
NSString *dashAuthor = [NSString stringWithFormat:@"%C %@", 0x2014, self.theme.quoteAuthor];
我现在如何更改正则表达式以反映这一点,因此它可以找到一个带有尾随em-dash的作者。
答案 0 :(得分:6)
您可以将em破折号与其unicode值(\u2014
)或字符名称匹配,如下所示:\N{EM DASH}
。