I am a little reluctant to give an answer using regular expressions, because it has been repeatedly stated that parsing HTML with a regular expression is considered harmful, impossible, dangerous to your mind, etc. And all this is correct, it is not my intention to demand something else.
But even after all these warnings, the OP explicitly asked for a regex solution, so I'm going to share this code. It can be, at least, useful as an example, how to change a line by going over all regular expression matches.
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) {
Output:
<div style="font-family:'Arial';font-size:21.5px;color:#ffffff;"> <div style="font-size:6.0px;">
source share