Como capturar caracteres ** especiais indicados ** em um NSString e em negrito entre eles?
Estou tendo problemas para colocar em negrito qualquer caractere entre um par indicado de "**". Por exemplo, neste NSString:
"The Fox has ran **around** the corner."
deve ler: "A raposa correupor aí a esquina"
aqui está o meu código:
NSString *questionString = queryString;
NSMutableAttributedString *mutableAttributedString = [[NSMutableAttributedString alloc] initWithString:questionString];
NSRange range = [questionString rangeOfString:@"\\*([^**]+)\\*" options:NSRegularExpressionSearch|NSCaseInsensitiveSearch];
if (range.location != NSNotFound) {
[mutableAttributedString setAttributes:@{NSFontAttributeName:[UIFont fontWithName:AGHeavyFontName size:size]} range:range];
}
[[mutableAttributedString mutableString] replaceOccurrencesOfString:@"*" withString:@"" options:NSCaseInsensitiveSearch range:NSMakeRange(0, queryString.length)];
return mutableAttributedString;
Estou tendo problemas - esse código ainda captura caracteres com um par de "*", portanto, neste caso,
"The fox has ran *around the corner*
ainda vai ler como "A raposa correupor aí a esquina ", quando não deveria.
Alguma ideia?