开发者社区> 问答> 正文

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 1684 0
1 条回答
写回答
取消 提交回答
  • 你可以通过em-dashUnicode 值: (\u2014 进行匹配,也可以用字符名:比如 \N{EM DASH} 进行匹配。

    2019-07-17 19:10:18
    赞同 展开评论 打赏
问答地址:
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载