I am a bit reluctant to give an answer using regular expressions, because it has been stated repeatedly that parsing HTML with regex is considered harmful, impossible, dangerous to your mind, etc. And all that is correct, it is not my intention to claim anything different.
But even after all that warnings, OP has explicitly asked for a regex solution, so I am going to share this code. It can at least be useful as an example how to modify a string by looping over all matches of a regular expression.
NSString *htmlString =
@"<div style=\"font-family:'Arial';font-size:43px;color:#ffffff;\">\n"
@"<div style=\"font-size:12px;\">\n";
NSRegularExpression *regex;
regex = [NSRegularExpression regularExpressionWithPattern:@"font-size:([0-9]+)px;"
options:0
error:NULL];
NSMutableString *modifiedHtmlString = [htmlString mutableCopy];
__block int offset = 0;
[regex enumerateMatchesInString:htmlString
options:0
range:NSMakeRange(0, [htmlString length])
usingBlock:^(NSTextCheckingResult *result, NSMatchingFlags flags, BOOL *stop) {
// range = location of the regex capture group "([0-9]+)" in htmlString:
NSRange range = [result rangeAtIndex:1];
// Adjust location for modifiedHtmlString:
range.location += offset;
// Get old point size:
NSString *oldPointSize = [modifiedHtmlString substringWithRange:range];
// Compute new point size:
NSString *newPointSize = [NSString stringWithFormat:@"%.1f", [oldPointSize floatValue]/2];
// Replace point size in modifiedHtmlString:
[modifiedHtmlString replaceCharactersInRange:range withString:newPointSize];
// Update offset:
offset += [newPointSize length] - [oldPointSize length];
}
];
NSLog(@"%@", modifiedHtmlString);
Output:
<div style="font-family:'Arial';font-size:21.5px;color:#ffffff;">
<div style="font-size:6.0px;">