开发者社区 问答 正文

NSRegularExpression检测破折号

正则表达式:

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的。

展开
收起
爵霸 2016-03-23 09:35:06 1742 分享 版权
1 条回答
写回答
取消 提交回答
  • 你可以通过em-dashUnicode 值: (\u2014 进行匹配,也可以用字符名:比如 \N{EM DASH} 进行匹配。

    2019-07-17 19:10:18
    赞同 展开评论
问答地址: