gpt4 book ai didi

iphone - NSRegularExpression 在 iOS 中检测 em-dash

转载 作者:行者123 更新时间:2023-11-28 18:23:14 26 4
gpt4 key购买 nike

我目前有以下正则表达式:

static inline NSRegularExpression * AuthorRegularExpression() {
if (!__authorRegularExpression) {
__authorRegularExpression = [[NSRegularExpression alloc] initWithPattern:@"-\\s*(.)*$" options:NSRegularExpressionCaseInsensitive error:nil];
}

return __authorRegularExpression;
}

正如您在模式中看到的那样,它检测到一个破折号 (-) 后跟一些字符串。但是现在我已经将破折号的格式更改为 em-破折号。所以字符串看起来像下面这样:

  NSString *dashAuthor = [NSString stringWithFormat:@"%C %@", 0x2014, self.theme.quoteAuthor];

我现在如何更改正则表达式以反射(reflect)这一点,以便它可以找到尾随 em-dash 的作者。

最佳答案

您可以使用它的 unicode 值 (\u2014) 或字符名称来匹配长破折号,例如:\N{EM DASH}

关于iphone - NSRegularExpression 在 iOS 中检测 em-dash,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16503609/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com