pattern = @"(\\$.*?\\$)";
regex = [NSRegularExpression regularExpressionWithPattern:pattern options:0 error:&error];
matches = [regex matchesInString:self options:0 range: searchedRange];
for (NSTextCheckingResult* match in matches) {
[string addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:[match range]];
}
私は上記のコードを使用して2つのドル記号の間にテキストを表示しています。だから、次の文字列でハローワールドテキストを削除ドル記号で、青色に着色されます:
@"This won't be blue. $hello world$. This won't be blue";
は今、しかし、私は青着色することがないように、単一のドル記号をしたいです。最初のドル記号がa-zA-Z0-9の文字に続いて、同様に2番目のドル記号の前にa-zA-Z0-9の文字が続くはずです。これどうやってするの?
ドルの間の内容は1文字にすることができますか? – rock321987