0

「and」と「the」という単語を正規表現検索から除外するために次のことを試しましたが、機能していないようです。私が間違っていることは何か分かりますか?

            NSString *pattern = [NSString stringWithFormat:@"\\b%@\\b\\b(?!.*\\b(?:and|the)\\b)", word];
        NSRegularExpression *regex = [[NSRegularExpression alloc] initWithPattern:pattern options: NSRegularExpressionCaseInsensitive error:nil];
4

1 に答える 1

1

Objective C は否定的な後読みをサポートしているようです。そのため、否定的な後読みに関する 2 つの優れた投稿をリンクします。

http://www.codinghorror.com/blog/2005/10/exception-matches-with-regular-expressions.html (ジェフ・アトウッド作)

http://www.regular-expressions.info/lookaround.html (上記のブログ投稿の 2 番目のリンク)

于 2012-06-25T13:29:59.103 に答える